How do I use a value of a pop-up menu (in the GUI) in an if-loop?

조회 수: 1 (최근 30일)
Pien_
Pien_ 2015년 6월 17일
댓글: Ingrid 2015년 6월 17일
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?

답변 (1개)

Ingrid
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
Pien_
Pien_ 2015년 6월 17일
I forgot to copy! Oops.
However, even with your adapted code, it still gives the same error. When I try to run it is also says: Function definition is misplaced or improperly nested.
Ingrid
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!

Translated by