フィルターのクリア

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 Center および File ExchangeLinear 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