作为一个快速的技巧,你可以做
global counter;
global RecursionDepth;
counter = 0;
RecursionDepth = 1000;
在你的代码开头的某个地方,那么你可以做
function IncrementCounterAndCheckDepth()
global counter;
global RecursionDepth;
counter = counter+1;
if counter > RecursionDepth
error('stack-overflow');
else
disp(RecursionDepth);
end;
return;
and insert it whenever necessary to check recursion. You can even add additional info/pass some arguments to it to improve your debugging, and once you are done with debugging, you can remove all globals and define IncrementCounterAndCheckDepth() to do nothing, so performance will not be affected, and for debugging it can be inserted in a lot of places without affecting performance. If you ever need to do additional debugging, you simply turn this function back on and modify is as required to track particular issue - you know it is everywhere in your code.