Maximum recursion limit of 500 reached. Use set(0,'Rec​ursionLimi​t',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.

it's fine working on another laptop but in my laptop will getting above error.........? can any one solve this....?
clear all;
close all;
a=imread('indus.jpg');
b=rgb2gray(a);
[m,n]=size(b);
r=im2double(b);
% r=im2bw(b,0.75);
% ^r=b;
out=r;
for i=2:m-1
for j=2:n-1
h=[1*r(i-1,j-1) 1*r(i-1,j) 1*r(i-1,j+1);...
1*r(i,j-1) 1*r(i,j) 1*r(i,j+1);...
1*r(i+1,j-1) 1*r(i+1,j) 1*r(i+1,j+1)];
out(i,j)=(median(median(h)));
end
end
r=out;
sobel=r;
for i=2:m-1
for j=2:n-1
h=[-1*r(i-1,j-1) 0*r(i-1,j) 1*r(i-1,j+1);...
-2*r(i,j-1) 0*r(i,j) 2*r(i,j+1);...
-1*r(i+1,j-1) 0*r(i+1,j) 1*r(i+1,j+1)];
sobel(i,j)=(mean(mean(h)));
end
end
sobel1=sobel;
for i=2:m-1
for j=2:n-1
h=[-1*sobel(i-1,j-1) -2*sobel(i-1,j) -1*sobel(i-1,j+1);...
0*sobel(i,j-1) 0*sobel(i,j) 0*sobel(i,j+1);...
1*sobel(i+1,j-1) 2*sobel(i+1,j) 1*sobel(i+1,j+1)];
sobel1(i,j)=(mean(mean(h)));
end
end
% a=min(r,sobel1);
% figure,imshow(a);
res=max(sobel1,r);
figure,imshow(res);
subplot(221);imshow(r,[]);
subplot(222);imshow(res,[]);
subplot(223);imshow(sobel,[]);
subplot(224);imshow(sobel1,[]);

 Accepted Answer

First, read this link to fix the formatting.
If you picked a name of your script that is the same as some function in your script, it will be called recursively, just as your partial error message states.
It's likely you called your script mean.m, sobel.m, or median.m.
I'm not sure because you didn't attach it, nor did you include the complete error message ( ALL the red text including the parts that identify the line of code throwing the error), nor did you tell us the name of your script.

4 Comments

im posted all the error message in my question ..?
DB, First, you didn't read the link I gave, did you? Because your code is still messed up.
Second, I saved your code as test3.m and ran your code and it finished with no errors. This is because I have a unique name. Did you read the part where I said the name is likely a problem? You didn't tell me the name of your script, so I think you might have overlooked that part.
Third, you are NOT including the error message. You're copying just a small snippet out of it. See Jan's answer. The full error message will also have things like the line number(s) and the lines of source code, none of which you posted. You need to include ALL the red text including the parts that identify the line of code throwing the error, and the name of your script, like I originally asked for.
@DB talari: Image Analyst's suggestions are valuable. Please consider them, because this will help readers to answer your questions efficiently in the future.
I've unaccepted my answer and accepted this one.

Sign in to comment.

More Answers (2)

Start with omitting the brute clearing header: "clear all; close all". This wastes time and is not useful in productive code.
An improtant detail is missing in the error message: Which line causes the error? This line will contain the name of the function, which is called recursively. I assume this will be the name of the script file you have posted.

5 Comments

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 reducem>dpalg
How to resolve this error?
SUSHMA MB: We need to see your code, and we need to know the file name you are using for your code.
please, the same error massage appear with me for this code
% function O=forward(x)
%
%
% busdata33=[1 0 0 0
% 2 100 60 0
% 3 90 40 0
% 4 120 80 0
% 5 60 30 0
% 6 60 20 0
% 7 200 100 0
% 8 200 100 0
% 9 60 20 0
% 10 60 20 0
% 11 45 30 0
% 12 60 35 0
% 13 60 35 0
% 14 120 80 0
% 15 60 10 0
% 16 60 20 0
% 17 60 20 0
% 18 90 40 0
% 19 90 40 0
% 20 90 40 0
% 21 90 40 0
% 22 90 40 0
% 23 90 50 0
% 24 420 200 0
% 25 420 200 0
% 26 60 25 0
% 27 60 25 0
% 28 60 20 0
% 29 120 70 0
% 30 200 600 0
% 31 150 70 0
% 32 210 100 0
% 33 60 40 0];
%
%
%
%
%
% % busdata69=[1 0 0 0
% % 2 0 0 0
% % 3 0 0 0
% % 4 0 0 0
% % 5 0 0 0
% % 6 2.6 2.2 0
% % 7 40.4 30 0
% % 8 75 54 0
% % 9 30 22 0
% % 10 28 19 0
% % 11 145 104 0
% % 12 145 104 0
% % 13 8 5 0
% % 14 8 5.5 0
% % 15 0 0 0
% % 16 45.5 30 0
% % 17 60 35 0
% % 18 60 35 0
% % 19 0 0 0
% % 20 1 0.6 0
% % 21 114 81 0
% % 22 5 3.5 0
% % 23 0 0 0
% % 24 28 20 0
% % 25 0 0 0
% % 26 14 10 0
% % 27 14 10 0
% % 28 26 18.6 0
% % 29 26 18.6 0
% % 30 0 0 0
% % 31 0 0 0
% % 32 0 0 0
% % 33 14 10 0
% % 34 19.5 14 0
% % 35 6 4 0
% % 36 26 18.55 0
% % 37 26 18.55 0
% % 38 0 0 0
% % 39 24 17 0
% % 40 24 17 0
% % 41 1.2 1 0
% % 42 0 0 0
% % 43 6 4.3 0
% % 44 0 0 0
% % 45 39.22 26.3 0
% % 46 39.22 26.3 0
% % 47 0 0 0
% % 48 79 56.4 0
% % 49 384.7 274.5 0
% % 50 384.7 274.5 0
% % 51 40.5 28.3 0
% % 52 3.6 2.7 0
% % 53 4.35 3.5 0
% % 54 26.4 19 0
% % 55 24 17.2 0
% % 56 0 0 0
% % 57 0 0 0
% % 58 0 0 0
% % 59 100 72 0
% % 60 0 0 0
% % 61 1244 888 0
% % 62 32 23 0
% % 63 0 0 0
% % 64 227 162 0
% % 65 59 42 0
% % 66 18 13 0
% % 67 18 13 0
% % 68 28 20 0
% % 69 28 20 0];
%
% % if(nbus==33)
% % busdata=busdata33;
% %
% % elseif(nbus==69)
% % busdata=busdata69;
% % end
%
% linedata=[1 1 2 0.0922 0.0470
% 2 2 3 0.4930 0.2511
% 3 3 4 0.3660 0.1864
% 4 4 5 0.3811 0.1941
% 5 5 6 0.8190 0.7070
% 6 6 7 0.1872 0.6188
% 7 7 8 0.7114 0.2351
% 8 8 9 1.0300 0.7400
% 9 9 10 1.0440 0.7400
% 10 10 11 0.1966 0.0650
% 11 11 12 0.3744 0.1238
% 12 12 13 1.4680 1.1550
% 13 13 14 0.5416 0.7129
% 14 14 15 0.5910 0.5260
% 15 15 16 0.7463 0.5450
% 16 16 17 1.2890 1.7210
% 17 17 18 0.7320 0.5740
% 18 2 19 0.1640 0.1565
% 19 19 20 1.5042 1.3554
% 20 20 21 0.4095 0.4784
% 21 21 22 0.7089 0.9373
% 22 3 23 0.4512 0.3083
% 23 23 24 0.8980 0.7091
% 24 24 25 0.8960 0.7011
% 25 6 26 0.2030 0.1034
% 26 26 27 0.2842 0.1447
% 27 27 28 1.0590 0.9337
% 28 28 29 0.8042 0.7006
% 29 29 30 0.5075 0.2585
% 30 30 31 0.9744 0.9630
% 31 31 32 0.3105 0.3619
% 32 32 33 0.3410 0.5302 ];
%
% % clc;
% % clear all;
% % close all;
% nbus=33;
% LD=linedata_radial_bus(nbus);
% BD=busdata_radial_bus(nbus);
% Sbase=100; % BASE MVA VALUE
% Vbase=12.66; % BASE KV VALUE
% Zbase=(Vbase^2)/Sbase; % BASE IMPEDANCE VALUE
% LD(:,4:5)=LD(:,4:5)/Zbase; % PER UNIT VALUES OF LINE R AND X
% BD(:,2:3)=BD(:,2:3)/(1000*Sbase); % PER UNIT VALUES LOADS P AND Q AT EACH BUS
% %N=max(max(LD(:,2:3)));
% Sload=complex(BD(:,2),BD(:,3)); % COMPLEX LOAD IN PER UNIT VALUES
% V=ones(size(BD,1),1); % INITIAL VALUE OF VOLTAGES
% Z=complex(LD(:,4),LD(:,5)); % LINE IMPEDANCE IN PER UNIT VALUES
% Iline=zeros(size(LD,1),1); % LINE CURRENT MATRIX
% Iter=100; % MAXIMUM NUMBER OF ITERATIONS
% % FOR BACKWARD-FORWARD SWEEP ALGORITHM
% %%
% for i=1:Iter
% % STARTING WITH BACKWARD SWEEP FOR LINE CURRENT CALCULATIONS
%
% Iload=conj(Sload./V);
% for j=size(LD,1):-1:1 % STARTING FROM THE END OF THE FEEDER
% c=[];
% e=[];
% [c e]=find(LD(:,2:3)==LD(j,3));
% if size(c,1)==1 % IF SIZE(C,1) IS ONE THAN BUS "J" IS STARTING OR ENDING BUS
% Iline(LD(j,1))=Iload(LD(j,3));
% else
% Iline(LD(j,1))=Iload(LD(j,3))+sum(Iline(LD(c,1)))-Iline(LD(j,1));
% end
%
% end
% % STARTING THE FORWARD SWEEP FOR BUS-VOLTAGE CALCULATION
% for j=1:size(LD,1)
% V(LD(j,3))=V(LD(j,2))-Iline(LD(j,1))*Z(j);
%
% end
%
% end
% Voltage=abs(V);
% Vangle=angle(V);
% PL=real(Z.*(abs(Iline.^2)));
% QL=imag(Z.*(abs(Iline.^2)));
% ptlosses=sum(PL) %total active power losses in p.u
% Qtlosses=sum(QL) %total reactive power losses in p.u
%
% Tl=sum(PL)*Sbase*1000;
% TQl=sum(QL)*Sbase*1000;
% %plot(Voltage)
% O=ptlosses
can you give me the solution of this problem
For one thing, the whole thing is commented out so I don't see how any errors could be produced. Then right after you assign line_data, you call clear all, essentially getting rid of all variables assigned up to that point.
What do you think you're passing in for x when you call forward()?
If you were getting the same error, then the answer to that problem has already been given. Either way, if you've read the thread enough to suspect it's similar, then you should have noticed that it's up to you to tell us what the error message actually is. You haven't done that.
What you pasted is entirely commented out. It will produce no errors, because it can't be executed. Even if the first layer of comments is removed, we still can't run your code, because we don't know what the inputs are, and we don't have the following functions/variables:
  • linedata_radial_bus
  • busdata_radial_bus
My suspicion is that you're trying to use the literal variables linedata and busdata33 in their place, but you never actually changed the code. As a side note, those two variables are unequal lengths, so you'll get indexing errors if you tried to index into the 33rd row -- but the code doesn't actually do subscript addressing. It just gets the 33rd element, which is either the number 33 or the number 1, which is almost certainly also wrong.
In other words, nobody knows what you're trying to do or what error you got. It could have been none, or any number of other errors, but it probably wasn't the error relevant to this thread.

Sign in to comment.

function [x,P]=ekf(fstate,x,P,hmeas,z,Q,R)
% EKF Extended Kalman Filter for nonlinear dynamic systems
% [x, P] = ekf(f,x,P,h,z,Q,R) returns state estimate, x and state covariance, P
% for nonlinear dynamic system:
% x_k+1 = f(x_k) + w_k
% z_k = h(x_k) + v_k
% where w ~ N(0,Q) meaning w is gaussian noise with covariance Q
% v ~ N(0,R) meaning v is gaussian noise with covariance R
% Inputs: f: function handle for f(x)
% x: "a priori" state estimate
% P: "a priori" estimated state covariance
% h: fanction handle for h(x)
% z: current measurement
% Q: process noise covariance
% R: measurement noise covariance
% Output: x: "a posteriori" state estimate
% P: "a posteriori" state covariance
%
% Example:
n=3; %number of state
q=0.1; %std of process
r=0.1; %std of measurement
Q=q^2*eye(n); % covariance of process
R=r^2; % covariance of measurement
f=@(x)[x(2);x(3);0.05*x(1)*(x(2)+x(3))]; % nonlinear state equations
h=@(x)x(1); % measurement equation
s=[0;0;1]; % initial state
x=s+q*randn(3,1); %initial state % initial state with noise
P = eye(n); % initial state covraiance
N=20; % total dynamic steps
xV = zeros(n,N); %estmate % allocate memory
sV = zeros(n,N); %actual
zV = zeros(1,N);
for k=1:N
z = h(s) + r*randn; % measurments
sV(:,k)= s; % save actual state
zV(k) = z; % save measurment
[x, P] = ekf(f,x,P,h,z,Q,R); % ekf
xV(:,k) = x; % save estimate
s = f(s) + q*randn(3,1); % update process
end
for k=1:3 % plot results
subplot(3,1,k)
plot(1:N, sV(k,:), '-', 1:N, xV(k,:), '--')
end
%}
% By Yi Cao at Cranfield University, 02/01/2008
%
[x1,A]=jaccsd(fstate,x); %nonlinear update and linearization at current state
P=A*P*A'+Q; %partial update
[z1,H]=jaccsd(hmeas,x1); %nonlinear measurement and linearization
P12=P*H'; %cross covariance
% K=P12*inv(H*P12+R); %Kalman filter gain
% x=x1+K*(z-z1); %state estimate
% P=P-K*P12'; %state covariance matrix
R=chol(H*P12+R); %Cholesky factorization
U=P12/R; %K=U/R'; Faster because of back substitution
x=x1+U*(R'\(z-z1)); %Back substitution to get state update
P=P-U*U'; %Covariance update, U*U'=P12/R/R'*P12'=K*P12.
function [z,A]=jaccsd(fun,x)
% JACCSD Jacobian through complex step differentiation
% [z J] = jaccsd(f,x)
% z = f(x)
% J = f'(x)
%
z=fun(x);
n=numel(x);
m=numel(z);
A=zeros(m,n);
h=n*eps;
for k=1:n
x1=x;
x1(k)=x1(k)+h*i;
A(:,k)=imag(fun(x1))/h;
end
The same error is showing to me kindly tell how to fix it

1 Comment

@Jay shankar Nanda: Note that inside ekf you call ekf. So when you first call ekf, it will run until the line where it calls ekf. Then it will call ekf, and run until it reaches the line where it calls ekf. Then it will call ekf, and run until it reaches the line where it calls ekf. Then it will call ekf, and run until it reaches the line where it calls ekf. Then it will call ekf, and run until it reaches the line where it calls ekf. Then it will call ekf, and run until it reaches the line where it calls ekf... etc., until your code reaches the recursion limit.
Is that your intent?
Note that your main functions inputs are all/mostly ignored within the function. It looks as if the main function should be renamed or perhaps converted to a script.

Sign in to comment.

Asked:

DB
on 11 Feb 2017

Edited:

DGM
on 30 May 2024

Community Treasure Hunt

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

Start Hunting!