MATLAB: Cycle depth limit 500 exceeded in MATLAB Function MATLAB Function. This could indicate an infinite cycle.

cycle depth exceededsimulink

I have received this error message, but I am not using an infinite loop:
function [t_winding,pc,pe] = fcn(ta,tw,net_torque,motor_speed)
tm = 0.5*(ta+tw);
B = 1.32-0.0012*(tm-293);
i = 0.561*B*net_torque
R = 0.0575*(1+0.0039*(tw-293));
pc = 3*i^2*R;
pe = (9.602e-06*(B*motor_speed)^2)/R;
t_winding = 0.455*(pc+pe)+ta;
if (abs(t_winding-tw)) > 1
[t_winding,pc,pe] = fcn(ta,t_winding,net_torque,motor_speed);
end
end

Best Answer

Your function is an infinite recursion. Within your fcn() function, you are calling the fcn() function. Your code reduces to:
function fcn(x)
fcn(x)
which means the fcn function is calling itself over and over again. It's like an M.C. Escher painting.