Y axis named after a String value from a listbox selection

3 views (last 30 days)
______________________________________________________________________
I would like my Y axis to be named after a String value from a listbox selection. I have many Strings,named Anna, Maria,Eva,etc. I did this so far:
______________________________________________________________________
Locate_list=findobj(gcf,'Tag','Listbox'); % locate listbox
*String_Value* =get(Locate_list,'Value'); % get string number
........
ylabel(['Name:', *String_Value* ]);
______________________________________________________________________
It gives me a Y label with the number of the string in the list. I would like to have the string name itself. For example:
Name: Anna
instead of:
Name: 2
______________________________________________________________________
Any ideas?

Accepted Answer

Lina
Lina on 25 Mar 2015
Figured it out! I had to use
Locate_list=findobj(gcf,'Tag','Listbox'); % locate listbox
String=str2num(get(Locate_list,'String'));
String_Value =get(Locate_list,'Value'); % get string number
figure('...')
.....
.....
ylabel(['Name:', num2str(*String*(*String_Value*)) ]);
And I get a nice label including the text:
Name: Anna , where Anna was in the listbox as a one of the strings :)

More Answers (1)

dpb
dpb on 10 Mar 2015
In what variable array are the strings stored for the dialog listbox? Use the index returned into that array to retrieve the value...
ylabel(ThatStringArrayOfStrings(String_Value))
The above presumes a cellstring array; use the 2D addressing from with a character array
ylabel(ThatStringArrayOfStrings(String_Value,:))
I don't know gui's well enough but I'd think there's a more direct access to the listbox return value than findobj and get, though? Look thru the examples for guidance there or maybe a GUI guru will drop in...

Categories

Find more on Desktop in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!