Get selection index for DropDown object using AppDesigner
조회 수: 60 (최근 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?
댓글 수: 0
채택된 답변
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
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 Center 및 File 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!