Error evaluating sectioned code

6 次查看(过去 30 天)
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 中查找有关 Entering Commands 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by