App designer: How to determine answer using value from dropdown List

6 views (last 30 days)
I've been trying to programm an app that estimates energy consumption in a household.
For a given appliances the inputs are:
  • Number of selected appliances: dropdown list you can choose from. (variable "q1" in code)
  • Energy consumption: dropdown list that lists usual engergy consumtion for the appliances (variable "ee1" in code), but also an edit field if you know the exact value (variable "e1" in code).
  • Number of hours the appliance is used in a day: edit field (variable "n1" in code).
I've create the callbacks for the button "estimate" as such:
Explanation on Why i used The "if...else...end" : when the user inputs an exact value of the energy consumption of the appliance the answer will be calculated using that value. but if the edit field =0 than the value from the dropdown list is used.
These are the issues i am getting:
-When i put values after i run the program, the value that is calculates seems random and does not look like it was calculated using the values i've inserted, The answer is totally wrong.
-When i select a value for the energy usage from the dropdownlist this is the message that appears:
Please note this the first time i am using this program, my level is lower than that of a beginner. I would appreciate if the your answers were as basic as possible.

Accepted Answer

Image Analyst
Image Analyst on 9 Apr 2022
Not sure with App Designer (I'm still using GUIDE) but the Value property might be the index of the item selected, not the contents that you see displayed in the dropdown. At least if it's like GUIDE, we'd do this
selectedItem = app.ouchoisirlestimateionDropDown.Value; % 1, 2, 3, etc.
allItems = app.ouchoisirlestimateionDropDown.String; % The contents -- what the user sees displayed.
% Extract just the contents of the one single selected item:
q1 = allItems{selectedItem}
  1 Comment
Clemence Ndiaye
Clemence Ndiaye on 9 Apr 2022
Thank you so much for taking the time to reply.
For the values in the dropdown list i just added str2double () to fix the error message.

Sign in to comment.

More Answers (0)

Categories

Find more on Computational Geometry in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!