functions suddenly connected after restart

조회 수: 3 (최근 30일)
Marc Laub
Marc Laub 2019년 8월 11일
편집: dpb 2019년 8월 11일
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.

채택된 답변

dpb
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by