Azzera filtri
Azzera filtri

Flag command !!

9 visualizzazioni (ultimi 30 giorni)
Bestun
Bestun il 29 Mar 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 Commento
Bestun
Bestun il 29 Mar 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)

Accedi per commentare.

Risposta accettata

Geoff
Geoff il 29 Mar 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 Commenti
Geoff
Geoff il 29 Mar 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 il 29 Mar 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Linear Programming and Mixed-Integer Linear Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by