How do I use a value of a pop-up menu (in the GUI) in an if-loop?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Ingrid
2015-6-17
编辑:Ingrid
2015-6-17
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 个评论
Ingrid
2015-6-17
I do not think the mistake is in this code but somewhere else in your file which is difficult to assess here
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!