Filter löschen
Filter löschen

Flag command !!

9 Ansichten (letzte 30 Tage)
Bestun
Bestun am 29 Mär. 2012
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 Kommentar
Bestun
Bestun am 29 Mär. 2012
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)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Geoff
Geoff am 29 Mär. 2012
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 Kommentare
Geoff
Geoff am 29 Mär. 2012
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 am 29 Mär. 2012
"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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Linear Programming and Mixed-Integer Linear Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by