Cycle depth limit 500 exceeded in MATLAB Function MATLAB Function. This could indicate an infinite cycle.
古いコメントを表示
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
採用された回答
その他の回答 (1 件)
Guillaume
2018 年 7 月 11 日
0 投票
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.
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!