The line to expand/collapse the code disappears after I edited the script with text. The code fielding option is turned on in preferences. Is there any way to get it back?

3 commentaires

Mark Hayworth
Mark Hayworth le 4 Avr 2016
Did you try turning it off and then back on again? Perhaps restarting in between?
Matlab_Student
Matlab_Student le 4 Avr 2016
I did. I even opened the code with another computer and it too did not display the line.
matthew schwarz
matthew schwarz le 9 Jan 2022
Modifié(e) : matthew schwarz le 9 Jan 2022
So i had a similar problem to OP, that others who find themselves here might find useful.
I currently use the hack
##
Stuff i want folded
##
However Ctrl+Shift+. was not folding code and i could not see + in the margin despite all boxes in settings ticked.
You have to right click on the margin/breakpoint and look for "Show Code Folding Margin".
Now the + appears where you can fold code.

Connectez-vous pour commenter.

 Réponse acceptée

Steven Lord
Steven Lord le 4 Avr 2016

2 votes

In my experience usually that means that there's some syntactic error in the file that prevents it from being a valid MATLAB program file. Look in the upper-right corner; do you see a red square? If so, Code Analyzer is telling you that there's an error that WILL prevent the script / function / class from executing and there should be a red line in the right margin that will indicate where it believes the error to be. Correct the error to make the file a valid MATLAB program file and you should be able to fold sections of it again.

5 commentaires

Matlab_Student
Matlab_Student le 4 Avr 2016
This is exactly the cause of the problem! Thank you so much!
Steven Lord
Steven Lord le 4 Avr 2016
In that case, please accept this answer. Thanks!
Lenny Cabibbo
Lenny Cabibbo le 7 Nov 2018
Hello, I have exactly the same issue with Matlab R2018b, only on one file. I check my preference>code Folding, everything is check. I restart Matlab, my computer, still the same.
Even when I right click the Fold section is disable.
Thank you
madhan ravi
madhan ravi le 7 Nov 2018
Modifié(e) : madhan ravi le 7 Nov 2018
Accepted answer by madhan ravi since the OP didn’t.
Lenny Cabibbo, check the upper-right corner of the Editor as I described in my original answer. Likely your code is not syntactically valid, so MATLAB would not know how (or how much) to fold.
Consider the case of two nested for loops with one end.
for k = 1:10
for j = 2:5
x(k) = k;
y(k) = k.^j;
disp('Hello');
end
Should MATLAB fold from the line "for j = 2:5" until the line "end", assuming that the end keyword was intended to end that for loop and leaving the outermost one unterminated? That would be incorrect if the missing end statement was supposed to be before the disp line.
Or should MATLAB fold from "for k = 1:10" to the "end", being "greedy" to try to fold as much code as possible?
Make your code syntactically valid and code folding should be enabled.

Connectez-vous pour commenter.

Plus de réponses (1)

David Tanis
David Tanis le 8 Nov 2020
Modifié(e) : David Tanis le 8 Nov 2020

0 votes

Hi, So building on this question: How come matlab suddenly decided overnight there were too many errors? And more importantly, how can I fix it quickly? My whole code was based on a sort of improvised foldable userinterface, that has now disappeared. To be clear, my code wasnt made to run in one go, only code sections were intended to be viable.
Any help would be much appreciated.

1 commentaire

David Tanis
David Tanis le 8 Nov 2020
I solved it: I left a 'switch' somewhere unattended.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by