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.
Show older comments

1 Comment
Greg
on 1 Dec 2018
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?
Answers (2)
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 Comments
Take out the [] in the items data list and just put numbers, it should come out as double. Replace the brackets with 0 or NaN or Inf if you must have "Select" as a dropdown value.
Also, you aren't pulling the dropdown's value in your button callback. You can't add the dropdown itself to another.
madhan ravi
on 1 Dec 2018
Okay so yes each option will be assigned a value according. Then each value will essentially be added together to get a total number which will dictate the output. As you can see below I have values for each. I want the select option to not work and force one to choose male or female.

Then i am trying to program the done button to do something like this where it displays the number into the box. Eventually I want it to display 'fatal' if the number reaches over 100, and 'not fatal' if it falls below 100. Bu

Right now the app designer creates the item data like so below. You can see with { } it is making a string rather than using [ ] to get numerical values. When I hit run I get errors saying it isn't numerical and it is a string. I have researched a lot and people seem to say it is a bug. I have seen people use str2double to change it. I am just very lost.

Jonathan Patten
on 1 Dec 2018
Greg
on 1 Dec 2018
This isn't what you are getting, it is what you are using. What are the actual results? I don't understand what you meant by "still seems to be a matrix."
As far as I can tell from here, that looks like it will do what you want.
Jonathan Patten
on 1 Dec 2018
Jonathan Patten
on 1 Dec 2018
Greg
on 1 Dec 2018
I've updated my answer. I built a MWE, but I can't attach .MLAPP files to my answer...
Jonathan Patten
on 1 Dec 2018
Jonathan Patten
on 1 Dec 2018
Greg
on 2 Dec 2018
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
on 29 Jun 2020
Edited: Jan Siegmund
on 29 Jun 2020
@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
on 21 Nov 2021
0 votes
Just add constraint to the parameter, you can edit this parameter to have a rule, the role will be int16 e.g. ..
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
