Get multiples item from listbox
15 次查看(过去 30 天)
显示 更早的评论
Dear all,
I have a listbox in a GUI from which I want to retrieve the value of different items. I have set up the "Max" value to 2 (and the "Min" to 0). With this I can select 2 items in my list. But, when I want to get the value of the two selected items with:
contents = cellstr(get(hObject,'String'))
selected_file=contents{get(hObject,'Value')}
It is only giving me the value of the first item in the list as a string.
How I can get an array of the two selected items then? I'm sure it is very simple but I can't find the solution.
Thanks for your help.
0 个评论
回答(3 个)
Nicolas Giret
2017-2-2
1 个评论
Adam
2017-2-2
Well in your original question you extracted the string into contents so I used what you had written there and didn't bother to repeat it.
Jan
2017-2-2
编辑:Jan
2017-2-2
Older Matlab versions contained the function popupstr for this job. Unfortunately this small but useful piece of code has been removed. Here is a replacement, which handles single and multi-selction listboxes and popup menus, strings, CHAR matrices and cell strings:
selected_items = GetSelection(hObject)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!