Error evaluating sectioned code

조회 수: 17 (최근 30일)
Chad Greene
Chad Greene 2018년 2월 27일
댓글: Chad Greene 2018년 2월 28일
I recently updated from R2014b to R2017b, and I've noticed a new, somewhat annoying behavior. In older versions of Matlab, I could section my code like this:
%%Section 1:
x = 1 + 2;
%%Section 2:
y = [5 ;
Sectioning code makes it easy to evaluate one chunk at a time, while I'm still working on other parts of the script. Just put the cursor anywhere in Section 1, hit Ctrl+Enter, and it'll evaluate everything in Section 1. However, R2017b now refuses to calculate anything unless the entire script is in perfect working order. If I try to evaluate Section 1 of the code above I get this error:
Error: File: test.m Line: 7 Column: 11
This statement is incomplete.
Yes, Matlab, I know. I'm still working on Section 2, but can I just evaluate Section 1? Is there any way to get the old behavior back?

채택된 답변

Rik
Rik 2018년 2월 27일
As far as I can tell, there is no way to turn this off. See also this question. The point is that if the syntax is incorrect in one section, Matlab can't enable local functions and apparently the editor is not smart enough to see that you don't have local functions in your script.
The only way I found is to comment out the section that have still an incorrect syntax (with %{ and %}, as I presume you are aware).
Local functions can be useful in debugging, but I don't know if I agree with the design principle. I'm not really using Matlab long enough to be old-fashioned, but I'm getting the feeling I am. I don't see the advantage of live scripts over sections either.
  댓글 수: 1
Chad Greene
Chad Greene 2018년 2월 28일
Interesting, thanks Rik. It's a shame that this change was made. Definitely makes coding less user friendly for me.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by