App Designer ListBox and DropDown selection number

18 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Ashutosh Prasad
Ashutosh Prasad el 24 de Ag. de 2018
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
  2 comentarios
Jurgens Wolfaardt
Jurgens Wolfaardt el 27 de Ag. de 2018
Thank-you. That solves it!
Kristoffer Walker
Kristoffer Walker el 3 de Dic. de 2022
Excellent development option

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by