[GUI] How do you get only one element in a listbox

I know you are able to obtain all the elements in a string from the listbox with:
get(handles.listbox1, 'String')
But what if I only want the second or fourth element in the listbox?
Thanks in advance <3

 採用された回答

Image Analyst
Image Analyst 2012 年 12 月 17 日

1 投票

You have to read in the whole thing anyway. Then get the value property and use that to index into the string.
listboxItems = get(handles.listbox1, 'string');
selectedItems = get(handles.listbox1, 'value');
selectedItem = listboxItems(selectedItems);

4 件のコメント

Shane
Shane 2012 年 12 月 17 日
Sorry I am still confused can you give an example to grab the 2nd element in a listbox?
Shane
Shane 2012 年 12 月 17 日
Ok I understand it now, Although I only get the first letter of the element.
and not the whole element?
So if the elements are "fish, dog, goat, rhino" and I select dog and hit my push button I only get "d" as my output and not dog.
<3
Walter Roberson
Walter Roberson 2012 年 12 月 17 日
Change
listboxItems = get(handles.listbox1, 'string');
to
listboxItems = cellstr( get(handles.listbox1, 'string') );
Shane
Shane 2012 年 12 月 17 日
Thank you soo much Walter I appreciate it!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Desktop についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by