After an if-exist block, why does script stop executing? In example below the code never gets to the final line. I feel that regardless of the state of the if block, the final line should execute. If I comment out the if and end lines, then I do get to the final line.
IniParamFlag=1;
if exist('Params','var')==1,
IniParamFlag=menu('Initialize parameters','yes','no');
end
IniParamFlag

댓글 수: 3

Adam
Adam 2016년 6월 29일
Seems to work fine for me.
John Knowles
John Knowles 2016년 6월 30일
Interesting. What version are you using? I'm on MATLAB Version: 8.6.0.267246 (R2015b). I find that if the condition evaluates to '1', then the code inside the if/end is executed, but nothing after the end. If instead it evaluates to zero, then nothing further is executed.
Adam
Adam 2016년 6월 30일
R2016a

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 29일

1 개 추천

You appear to have a control-Z immediately after your 'end' as the very next character.

댓글 수: 5

John Knowles
John Knowles 2016년 6월 30일
I'm not sure what a control-Z character is, but in any case I could not spot any characters folllowing the end. Just to be sure I tried terminating the lines with semi-colons and it made no difference. Could you please explain further if it looks like I misunderstood your reply?
Image Analyst
Image Analyst 2016년 6월 30일
편집: Image Analyst 2016년 6월 30일
Put the cursor after the "d" in "end" and hit delete. You may not see any effect because it will delete an invisible character. But it will run after that.
Alternatively, hit the end key and then the backspace key to delete your control-Z character.
By the way, you shouldn't put a comma at the end of your if line, though it doesn't harm anything - it's just not standard coding practice.
If you go back up to your initial question here and click on the pencil to edit your question, and look at your code, then as the first next character after end you will see a little rectangular box with some writing in it. That writing is
00
1A
and a box with 001A in it is the representation for a character that has no glyph in the font but whose hex representation is 001A which is decimal 26 which is control-Z .
John Knowles
John Knowles 2017년 1월 7일
편집: John Knowles 2017년 1월 7일
Thank you Walter and Image Analyst for taking the time to explain this. I somehow missed your last replies until now, when I got hit with a new instance of the problem. You were exactly right and the problem is now solved.
Stephen23
Stephen23 2017년 1월 7일
편집: Stephen23 2017년 1월 7일
This is a good example of where Notepad++ is an extremely handy text editor to have around: the menu View -> Show Symbol has a number of options, and makes finding bugs like this one easy.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

질문:

2016년 6월 29일

편집:

2017년 1월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by