App Designer ListBox and DropDown selection number

20 次查看(过去 30 天)
Hi All
I'm a GUIDE user but am now doing my first major GUI with App Designer (in 2017b), due to a nudge from Mathworks.
In GUIDE, the current selection number of a ListBox is extracted by handles.ListBox.Value (and for a DropDown, it is handles.DropDown.Value). In App designer the 'Value' field has been changed to output the content string of the selected entry and not the number of that entry. I can't find any field giving me the number? (which seems a step backwards to me in the context of vectorized code being the way to go)
Currently, I am awkwardly finding the number with strcmp inside a for loop.
for i = 1:length(app.DropDown.Items)
if strcmp(app.DropDown.Items{i},app.DropDown.Value)
break
end
end
SelectNum = i;
How do I obtain the number in a quick way?
Thanks in advance

采纳的回答

Ashutosh Prasad
Ashutosh Prasad 2018-8-24
Hello
You can use the ItemsData property of the app.DropDown class to specify whether you want the app.DropDown.Value to be numeric or string.
If you want numeric values just change the above code fragment with the following code snippet
>> app.DropDown.ItemsData = 1:length(app.DropDown.Items)
>> SelectNum = app.DropDown.Value;
Let me know if this works for you

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by