Effacer les filtres
Effacer les filtres

How to assign values to popup menu in GUI?

6 vues (au cours des 30 derniers jours)
Quan Seah
Quan Seah le 23 Avr 2018
I have a GUI to calculate the resistance of a resistor based on the number of bands and the color orders. I have 10 different colours, such as black, brown, red etc. I had tried to assign values to each color by using the following codes:
contents = cellstr(get(hObject,'string'));
popChoice = contents(get(hObject,'value'));
if strcmp(popChoice,'Black')
popVal = 0;
elseif strcmp(popChoice,'Brown')
popVal = 10;
elseif strcmp(popChoice,'Red')
popVal = 20;
elseif strcmp(popChoice,'Orange')
popVal = 30;
elseif strcmp(popChoice,'Yellow')
popVal = 40;
elseif strcmp(popChoice,'Green')
popVal = 50;
elseif strcmp(popChoice,'Blue')
popVal = 60;
elseif strcmp(popChoice,'Violet')
popVal = 70;
elseif strcmp(popChoice,'Grey')
popVal = 80;
elseif strcmp(popChoice,'White')
popVal = 90;
end
assignin('base','SecondColor',popVal)
The codes I used above actually works but all it does is saved the value into workspace and I have no idea how to use the value that's saved in the workspace to do calculation. Additionally, I had another function file that will do all the calculation based on the information gathered but I also have no clue on how to actually use it in GUI.Please help.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Avr 2018

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by