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!