How do I set numerical values to options in a dropdown menu made on appdesigner? I will have multiple drop down menus, the the options in each drop down will need their values added together and display the result.

조회 수: 45 (최근 30일)
Capture.PNG
  댓글 수: 1
Greg
Greg 2018년 12월 1일
Can you provide more detail? None of your dropdowns appear to be numeric. Are you trying to quantize the non-numeric options, say for gender: male = 1 and female = 2?

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

답변 (2개)

Greg
Greg 2018년 12월 1일
편집: Greg 2018년 12월 1일
If my assumption in the comment above is accurate, this is a perfect use of the "ItemsData" property of AppDesigner components. The "Items" [male,female] will display in the dropdown list, but the "Value" property will take from the "ItemsData" [1,2] list. Then it's a simple matter of accessing and adding the .Value of each dropdown of concern.
Edit: after investigation, it appears there is no way in "Design View" to make the ItemsData numeric. This is a shame because the tooltip explicitly says "1 x n numeric array" is valid. You can either use str2double, or set the ItemsData in the startupFcn.
  댓글 수: 11
Greg
Greg 2018년 12월 2일
Email sent.
MWE = Minimum Working Example. It is an example that fully reproduces the problem or behavior of interest, without anything additional. They are great for troubleshooting (bug reports) because you can avoid the confusion of your other code that has nothing to do with the issue.
Jan Siegmund
Jan Siegmund 2020년 6월 29일
편집: Jan Siegmund 2020년 6월 29일
@Jonathan Patten Simple, just use the cell of string numbers throughtout your callbacks and whenever you need numeric data, use str2double(app.Dropdown.ItemsData). However MATLAB should let us use numeric data in the first place.

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


Waleed Sahhary
Waleed Sahhary 2021년 11월 21일
Just add constraint to the parameter, you can edit this parameter to have a rule, the role will be int16 e.g. ..

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by