Y axis named after a String value from a listbox selection

3 次查看(过去 30 天)
______________________________________________________________________
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?

采纳的回答

Lina
Lina 2015-3-25
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 :)

更多回答(1 个)

dpb
dpb 2015-3-10
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...

类别

Help CenterFile Exchange 中查找有关 Desktop 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by