- Get the string property in "temperature" field and convert the string to a number using str2double()
- get the C/F selection from the dropdown menu
- Use a switch-case or a conditional statement (if) to create actions for c->f and f->c conversions. Each section will produce a converted temperature.
- Convert the converted temperature to a string using num2str()
- Update the string property in the "result" field
- Update the C or F symbol to the right of the Result field.
convert celsius to fahrenheit with a popupmenu
4 views (last 30 days)
Show older comments
Hi guys, i need your help with something:
I need a program to convert celsius to fahrenheit
on my GUI i have 2 edittext and and 1 popupmenu and 3 buttoms
i have to insert 1 value on the edittext 1, select the value to convert with the popupmenu (in this case fahrenheit)
and when i do clic on the bottom calculate, the value in celsius should be print on the edittext 2.
I hope you guys can help me with the code.
0 Comments
Answers (1)
Adam Danz
on 6 Sep 2019
Edited: Adam Danz
on 6 Sep 2019
The callback function to the "calculate" button should do the following,
I'm not sure if you're using app designer, guide, or uicontrol so I can't be more specific but if you need help with any of those steps, feel free to leave comments.
Here's a template that needs adapted to your situation. Hopefully the variable names are self explanatory.
inputTemp = temperatureHandle.String; % input temperature string
inputTempNum = str2double(inputTemp); % input temperature number
selectedConversion = menuHandle.String(menuHandle.Value); % selected conversion cell-string
switch selectedConversion{1}
case 'Celcius' %must be an exact match to the menu string
% convert C to F
outputTemp = (inputTempNum x (9/5)) + 32;
outputSymbol = 'F';
case 'Fahrenheit' %must be an exact match to the menu string
% convert F to C
outputTemp = (inputTempNum - 32) x (5/9);
outputSymbol = 'C';
end
outputString = sprintf('%.2f',outputTemp); % output temperature rounded to 2dp
resultHandle.String = outputString; % assign the temperature output
outputSymbolHandle.String = outputSymbol; % assign the temperature output symbol
9 Comments
See Also
Categories
Find more on Migrate GUIDE Apps 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!