필터 지우기
필터 지우기

App Designer ListBox and DropDown selection number

조회 수: 15 (최근 30일)
Jurgens Wolfaardt
Jurgens Wolfaardt 2018년 8월 21일
댓글: Kristoffer Walker 2022년 12월 3일
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
  댓글 수: 2
Jurgens Wolfaardt
Jurgens Wolfaardt 2018년 8월 27일
Thank-you. That solves it!
Kristoffer Walker
Kristoffer Walker 2022년 12월 3일
Excellent development option

댓글을 달려면 로그인하십시오.

추가 답변 (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