필터 지우기
필터 지우기

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