Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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."

765 views
Skip to first unread message

Jamuna

unread,
Jan 19, 2012, 4:51:10 AM1/19/12
to
This is the code
img = imread('eye.bmp');
imshow(img);
I=im2bw(img);
imgBW = edge(I);
rad = 24;
[y0detect,x0detect,Accumulator] = houghcircle(imgBW,rad,rad*pi);
figure;
imshow(imgBW);
hold on;
plot(x0detect(:),y0detect(:),'x','LineWidth',2,'Color','yellow');
figure;
imagesc(Accumulator);
I keep getting the error.
please help me

Steven_Lord

unread,
Jan 19, 2012, 9:40:00 AM1/19/12
to


"Jamuna " <jamunaj...@gmail.com> wrote in message
news:jf8p2e$m5$1...@newscl01ah.mathworks.com...
Try executing the code one line at a time until you receive the error. On
the line that caused the error, use the WHICH function to determine what
version of the function is being called. Check that function file and ensure
that if the function is calling itself recursively that there is a way for
the recursion to end.

For example:

function y = myfactorial(n) % incorrect
if n < 2 % This isn't technically correct, but good enough for this example
y = 1;
else
y = n*myfactorial(n+1); % whoops, should have been n-1
end

Note that if n starts out greater than 2, myfactorial will be called with
greater and greater values and eventually you'll reach the RecursionLimit.
If on the other hand you fixed that bug it would be called with ever
decreasing values and you'd only reach the RecursionLimit if you asked for
the factorial of a large number.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Mehryar

unread,
Apr 4, 2013, 11:32:15 AM4/4/13
to
Try this in Matlab's workspace:

set(0, 'RecursionLimit', 100000)

Then run your code again.


"Jamuna " <jamunaj...@gmail.com> wrote in message <jf8p2e$m5$1...@newscl01ah.mathworks.com>...

Elnaz

unread,
Jul 27, 2014, 5:22:11 AM7/27/14
to
"Jamuna " <jamunaj...@gmail.com> wrote in message <jf8p2e$m5$1...@newscl01ah.mathworks.com>...
Just save m-file in default directory of matlab, close the m-file and again open it. then you wont see the message any more, at least for my case .

Devdatt Thengdi

unread,
Aug 28, 2017, 7:20:26 AM8/28/17
to
Getting same error for minimizing sin(x) over 0 to 2*pi.
Function File:

function fun = SinExample(x3);
x1 = 0;
x2 = 2.*3.14178;
fun = sin(x3);
x3 = fminbnd(@SinExample,x1,x2)

Solution File:

x1 = 0;
x2 = 2.*3.14178;
set(0,'RecursionLimit',1100);
x3 = fminbnd(@SinExample,x1,x2)

Software crashes for anything beyond N=1100. No solution.

winwin...@gmail.com

unread,
Aug 28, 2017, 7:49:25 AM8/28/17
to
Jamuna於 2012年1月19日星期四 UTC+8下午5時51分10秒寫道:
【数亿娱乐】【Q1192431153】【直属主管招商总代开户】【加我备注88】 数亿娱乐隆重登场 新濠集团旗下 实力雄厚信誉优秀 您不能错过

winwin...@gmail.com

unread,
Aug 28, 2017, 7:50:43 AM8/28/17
to
Jamuna於 2012年1月19日星期四 UTC+8下午5時51分10秒寫道:

Steven Lord

unread,
Aug 28, 2017, 10:50:26 AM8/28/17
to
"Devdatt Thengdi" wrote in message <oo0u9g$3be$1...@newscl01ah.mathworks.com>...
> Getting same error for minimizing sin(x) over 0 to 2*pi.
> Function File:
>
> function fun = SinExample(x3);
> x1 = 0;
> x2 = 2.*3.14178;
> fun = sin(x3);
> x3 = fminbnd(@SinExample,x1,x2)

Well, yes.

The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...
The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...
The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...
The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...
The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...
The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...
The SinExample function calls FMINBND. FMINBND calls SinExample. Then ...

There is no way to break out of that recursion.

> Solution File:
>
> x1 = 0;
> x2 = 2.*3.14178;
> set(0,'RecursionLimit',1100);
> x3 = fminbnd(@SinExample,x1,x2)
>
> Software crashes for anything beyond N=1100. No solution.

Yes. The error message you received when you encountered the recursion warned that setting the RecursionLimit too high could cause MATLAB to crash.

https://en.wikipedia.org/wiki/Stack_overflow

The correct solution is not to call FMINBND with @SinExample as the objective function from within the SinExample function itself. In general, calling any of the "function functions" like the ODE solvers or any of the optimization or zero finding routines on a function from within that function itself smells funny.

https://en.wikipedia.org/wiki/Code_smell

function y = SinExample
x1 = 0;
x2 = 2*pi; % I assume you have an (inexact) approximation to pi in your original code
y = fminbnd(@sin, x1, x2)

--
Steve Lord
sl...@mathworks.com
To contact Technical Support, use the Contact Us link at the top of http://www.mathworks.com
0 new messages