functions suddenly connected after restart
4 次查看(过去 30 天)
显示 更早的评论
Hey there,
so i got a little problem. All started when my matlab didnt want to stop some calculations. I pressed ctrl+c like an idiot and pressed quit so many times, somehow it didnt work. in the command window some kind of problems wioth "eval" appeared. So i just shut down matlab and reopened it. From this point on my code didnt work anymore...
-All of my functions seem to be connected. Even if "function" and "end" of the specific function are the right places and if i hover over function it tells me where the correct end is, BUT the wight line on the left that embraces functions or loops, doenst stop at ends, but continues all the way down.
Additionally many varriables or indices are colored (or marked) as if they were global variables, but they are definitly not
I was able to "repair" some of my code. Some functions that were connected could be seperated by marking the whole function and align them with ctrl+i. There were aligned correctly before, so ctrl+i didnt change anything but getting rid of the interconnection white lign embrace.
Unfortunatley this does not work for all function, and im not sure what the generell problem is, that leads to this behaviour
My whole code should be attached below.
Many thanks in adavence if someone can help me with this.
Best regards.
0 个评论
采纳的回答
dpb
2019-8-11
编辑:dpb
2019-8-11
Apparently focus was in the editor and some of your keystrokes CTRL^C got interpreted to paste and some extra end statements were inserted at the end of the main function around line 520ff.
There also was a missing closing bracket and parenthesis on the extremely long ylim() line 342...I wrapped that line and reformatted indenting to be more consistent and closed up quite a lot of white space.
I'd strongly recommend refactoring the function to not have 500+ line function...
BTW, the problem was given in the main error message in the editor as unbalanced END statements.
Both missing or extra END and closing brackets/parentheses confuse the input parser greatly and can interact--particularly the [ ... missing the closing ] tries to just keep on agglomerating stuff...
ADDENDUM
BTW, I converted one nested if...elseif...end construct on the case_acc variable to a SWITCH block while was checking for where the broken END construct could be...much cleaner. But, while doing that I noticed
case 2
if trig>1.2 || err==1
i=i-1;
Content=Content_save;
delta=delta/1.5;
t=time(i-1)+delta;
elseif err==1
precip_dist=precip_dist2;
grains=grains_new;
end
in which the elseif block will never get triggered because the if clause is written as or and so if err==1 it's the clause that will be executed irrespective of the value of trig
Dunno if that's of any concern or not, but probably not what was intended, exactly.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!