Matlab 代码折叠在键入时消失/中断/禁用自身

Matlab code folding disappears / breaks / disables itself while typing

我想在我的 Matlab 编辑器中使用代码折叠,但在键入代码时折叠消失了。这是一个最小的例子:

在上面的示例中,我刚刚折叠了一个 for 循环,然后我开始编写下一个循环。但是我一输入“=”,代码折叠就消失了:

当我完成 for 循环时,折叠再次出现,但一切都展开了。

我联系了 Matlab 支持,这是他们的回复:

Under certain circumstances, when new code is written in the Editor, previously folded code unfolds. This is a known issue, and the development team is presently working on finding a solution and may address this issue in a future release of MATLAB.

因此看来目前您必须 "careful" 如何编写代码(如 Anthony 所建议的那样)以避免破坏折叠。

这只是问题的图形表示和 Anthony in his 建议的解决方法。


问题:

建议的解决方案 Anthony in his :

end放在循环首位可解决问题,如下所示:


用于此的随机代码:

p=0;
for k=1:10
p=p+k;
end

for l=1:10
p=p+l;
end

for m=1:10
p=p+m;
end