How do I use a value of a pop-up menu (in the GUI) in an if-loop?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
i'm writing an interface with the GUI for an oscilloscope. I want to use the value of a pop-up menu in an if-loop to determine the scale of my oscilloscope.
this is the code i wrote:
contents = get(handles.popupmenu1,'String');
energyLevel = contents(get(handles.popupmenu1,'Value'))
if strcmp(energyLevel, '100') | strcmp(energyLevel, '150')
set(deviceObj.Channel(1), 'Scale', 0.2);
set(deviceObj.Channel(2), 'Scale', 0.2);
else set(deviceObj.Channel(1), 'Scale', 0.5);
set(deviceObj.Channel(2), 'Scale', 0.5);
Only it gives the following error: A nested function cannot be defined inside a control statement (if, while, for, switch or try-catch).
Be aware that in addition to this message, other messages might appear in the file. Such as, statement might not be aligned with its matching END and Parse error at END: usage might be invalid MATLAB syntax. When you remove the nested function definition from the control statement, these other messages might disappear
I am not familiar with this error. Can somebody help me?
0 Commenti
Risposte (1)
Ingrid
il 17 Giu 2015
Modificato: Ingrid
il 17 Giu 2015
are you not just missing an end or did you forgot to copy it?
energyLevel = str2double(contents(get(handles.popupmenu1,'String')))
if or(energyLevel==100,energyLevel==150)
set(deviceObj.Channel(1), 'Scale', 0.2);
set(deviceObj.Channel(2), 'Scale', 0.2);
else
set(deviceObj.Channel(1), 'Scale', 0.5);
set(deviceObj.Channel(2), 'Scale', 0.5);
end
2 Commenti
Ingrid
il 17 Giu 2015
I do not think the mistake is in this code but somewhere else in your file which is difficult to assess here
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!