Cycle depth limit 500 exceeded in MATLAB Function MATLAB Function. This could indicate an infinite cycle.
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Guillaume
le 11 Juil 2018
0 votes
Your function is recursive, it calls itself. You've put a condition to stop the recursion when abs(t_winding-tw) is less than 1, unfortunately after calling itself 500 times the condition still hasn't been met. It's most likely a bug in your code.
If you did mean to recurse more than 500 times, there is a way to increase that limit. However, matlab puts the limit in the first place to protect you as each recursion consumes quite a lot of memory as it needs to create a new set of all the variables in your function.
To start debugging what is actually happening with your recursion, I would remove the semi-colon on the t_winding = ... line, so you can see how it evolves. If it doesn't decrease then you indeed have an infinite loop.
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!