MATLAB Answers


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.

Asked by Jonathan Patten on 30 Nov 2018
Latest activity Commented on by Greg
on 2 Dec 2018

  1 Comment

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?

Sign in to comment.

1 Answer

Answer by Greg
on 1 Dec 2018
Edited by Greg
on 1 Dec 2018

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.


What is a MWE? You can email it to me if you would like,
As to your updated response, I have seen a lot of people saying it is a bug with app designer. I've tried setting the item data in the startup function and it still failed. How and where would I use the str2double function?
Edit, working with the startup function, I am now getting results. I am still curious as to how to get results with str2double function.
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.

Sign in to comment.