Get selection index for DropDown object using AppDesigner

77 次查看(过去 30 天)
Using AppDesigner, how do I access the selected index of a DropDown menu. The Value is the selected string but I can't find anywhere that indicates the selected index. Instead I seem to have to do:
I = find(strcmp(h.Items,h.Value));
Is this really the suggested approach?

采纳的回答

Matt J
Matt J 2017-11-10
编辑:Matt J 2017-11-10
The h.Value property has different behavior depending on how h.Items and h.ItemsData are set up. If you define the ItemsData property to be some sequence of numeric indices i=1:N, then h.Value will be the numeric value of i corresponding to the selection.
  15 个评论
Erik
Erik 2021-2-19
Thanks on the info on how to get access to a running app.
There is no way in my version to enter the ItemData so that it becomes a numerical array. What ever I do in de compent inspector, the end result is the same (see below). And yes the (single) Value is shown in the inspector as numbers under each other while the ItemData is shown as 1,2,3,4
But, like I said, in the 2020b version, this behaviour fortunately changed apparently
>> app.DropDown
ans =
DropDown (Option 1) with properties:
Value: '1 2 3 4'
Items: {'Option 1' 'Option 2' 'Option 3' 'Option 4'}
ItemsData: {'1 2 3 4'}
Editable: 'off'
ValueChangedFcn: ''
Position: [131 192 100 22]

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by