From: Maxx on
Hello all,
How can I set the default items in a listbox to a txt array? Nothing I do in the property manager seems to work, so there has to be code. If I type:

set(handle,'string',txt)

the values change when I click on the default string 'lisbox', but I need it to say [txt] where the 'listbox' is displayed. Also, once a value in [txt] is selected by the user, how can I assign data to that selection/make the values update to a new string [txt2]? I'm not very good with callbacks yet, this is my first GUI.
Thanks
Maxx
From: ImageAnalyst on
Maxx:
Sounds like you're using GUIDE. Double click on the listbox to bring
up the "Property Inspector" (not "property manager"). Just to the
right of the word "String" in the left hand panel (which is the column
that contains all the property names) is a little icon/button with a
few lines in it. Click that and then type in whatever you want your
listbox to be initialized with.

When you click on an item, you can retrieve ALL the items in the
listbox by getting the string property. If you want to change the
list, you have to stuff a new string into the listbox using the set()
command.

Here's a GUI template/tutorial that may be helpful for you:
http://www.mathworks.com/matlabcentral/fileexchange/24224

From: Maxx on
Thanks ImageAnalyst for your time. I know I can use the, ahem, Property Inspector and manually change the default string. Problem is, further back in my code I extract the data from an Excel sheet that is constantly updated and changed. So I need the default string, if possible, to reflect the [txt] array edits as the Excel file is updated weekly. Is there code I can specify outside of PI? For instance:

handle=set(...,...,...,'cellstring', txt,)

Thanks again for your help.
Maxx
From: Matt Fig on
% You say you have a text array, I think you mean a character array.
txt = ['apple ';'banana';'orange';'grape ';'plum ';'pear ']; % A character array
set(uic_handle,'string',cellstr(txt)); % Use cellstr to convert your char array to a cell array.
From: Maxx on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i0biid$n03$1(a)fred.mathworks.com>...
> % You say you have a text array, I think you mean a character array.
> txt = ['apple ';'banana';'orange';'grape ';'plum ';'pear ']; % A character array
> set(uic_handle,'string',cellstr(txt)); % Use cellstr to convert your char array to a cell array.

Thats it man, thanks Matt. Everytime I set the listbox values though (in the code) the callback just skips to the last one.

set(handle,'string',txt1)
%when I click on this I want it to update to txt2, then txt 3, etc
set(handle,'string',txt2)
%but it skips txt1 and sets the values to txt2

How does Matlab reference its callback functions/how does it talk to code within callback?
Maxx