Error evaluating sectioned code

17 visualizzazioni (ultimi 30 giorni)
Chad Greene
Chad Greene il 27 Feb 2018
Commentato: Chad Greene il 28 Feb 2018
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?

Risposta accettata

Rik
Rik il 27 Feb 2018
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 Commento
Chad Greene
Chad Greene il 28 Feb 2018
Interesting, thanks Rik. It's a shame that this change was made. Definitely makes coding less user friendly for me.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by