Flag command !!

9 次查看(过去 30 天)
Bestun
Bestun 2012-3-29
Dear All I am using flag command in my code. But when I run it this error occurs
“??? 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” Any Help please Regards
  1 个评论
Bestun
Bestun 2012-3-29
And this is the flag section:
function HenXoma(flag, xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight)%
if (flag == 0)
dlorg(xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight);
else if (flag ==1)
HenXoma(flag, xmax, ymax, edgeA, edgeB, edgeC, edgeD, cohesion, phiDegs, unitWeight)

请先登录,再进行评论。

采纳的回答

Geoff
Geoff 2012-3-29
You are never changing flag, so you are recursing indefinitely.
Perhaps you meant to toggle the flag:
else if (flag ==1)
HenXoma(~flag, etc...
Or indeed:
HenXoma(0, etc...
  4 个评论
Geoff
Geoff 2012-3-29
Well, the first time you call HenXoma, I presume you pass the value '1' or 'true' for the flag. Inside the function, you test if the flag is true, and then call the function again. If you don't set the flag to false, then every time you call it will do the same thing (keep calling itself until your stack dies).
The unary operator ~ means 'not'. So ~0 is 1, and ~1 is 0. But I think it would be more concise in your case to just pass 0 instead of ~flag.
What I don't understand is WHY you are doing this recursion at all. In this case there is absolutely no difference between making the recursive call and then calling dlorg, versus just calling dlorg straight away without recursing first... Unless you haven't shown the rest of a larger function.
Jan
Jan 2012-3-29
"elseif" is written without space. "else if" does something else.
"flag" is a command also, see "help flag". As usual it is recommended not to reuse the name of toolbox functions for variables.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by