How to solve Maximum recursion limit of 500 reached problem

193 views (last 30 days)
Jia Zhen
Jia Zhen on 13 Nov 2014
Commented: Walter Roberson on 30 Mar 2016
Dear all, my matlab function is this
function eyescript(func, begin_in, end_in, args, ext)
if func==0
for i=begin_in;
fn=strcat(num2str(i),ext);
fprintf('\nRunning %s\n',fn);
symeye(fn,args(1),args(2),args(3),args(4));
end
else
for i=begin_in;
fn=strcat(num2str(i),ext);
fprintf('\nRunning %s\n',fn);
avgeye(fn,args(1), args(2));
end
end
when i want to call out this function eyescript i keep getting this error
eyescript(0,1,30,[0,0,0,0],'.jpg');
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to
change the limit. Be aware that exceeding your available stack space can crash
MATLAB and/or your computer.
Error in eyescript
What should i do to prevent this error from happening? Thanks in advance.
  3 Comments
Walter Roberson
Walter Roberson on 30 Mar 2016
You opened a Question about this, so it will be discussed in that Question.

Sign in to comment.

Accepted Answer

Ken Atwell
Ken Atwell on 14 Nov 2014
A recursion depth of 500 is "absurd", almost surely indicating a problem in the code and not some limitation in MATLAB. The recursion could be in symeye -- does it call itself, or call eyescript? Recursion problems can be tricky to debug. I recommend:
  1. Set breakpoint at the beginning of eyescript and run to it.
  2. Step OVER the calls to MATLAB functions like strcat and fprintf.
  3. Step IN to the call to symeye
  4. Continue this pattern until the program takes an unexpected turn.
PS: I second Adam's comment about your 'for' loop, it is likely not what you intend.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!