フィルターのクリア

Need help With "If" statement

1 回表示 (過去 30 日間)
Andrew
Andrew 2011 年 2 月 18 日
Hi everyone,
I have an if statement that looks like the following:
if ( n == 0 && m == 0 )
values = 1;
elseif ( n < 0 || m < 0 )
display('no')
elseif ( n == 1 && m == 1 )
w11 = sqrt(3);
values = w11*sqrt((1-cos(theta).^2))*pnmnew(m-1,m-1,theta,norm);
elseif (n == m )
wmm = sqrt((2*m+1)/(2*m));
values = wmm.*(1-cos(theta).^2).^(1/2).*pnmnew(m-1,m-1,theta,norm);
wnm = sqrt(abs(((2*n+1)*(2*n-1))/((n+m)*(n-m))));
wnmB = sqrt(abs(((2*(n-1)+1)*(2*(n-1)-1))/(((n-1)+m)*((n-1)-m))));
values = wnm*(cos(
elseif ( n ~= m )theta).*pnmnew(n-1,m,theta,norm)-(wnmB)^(-1)*pnmnew(n-2,m,theta,norm));
I was wondering how I could go from displaying "no" in the elseif statement to terminating it. I don't want it to recursion through values < 0. How would I make it so it ends when it hits that condition?
Thanks!

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 2 月 18 日
See return, place it after:
display('no')
Oleg

その他の回答 (2 件)

Matt Fig
Matt Fig 2011 年 2 月 18 日
I don't know what you mean by "I don't want it to recursion through values <0."
An IF statement is not a recursive thing. If you mean you want the function evaluation to stop where the DISP statement is, put a call to RETURN there.
  2 件のコメント
Andrew
Andrew 2011 年 2 月 18 日
Yes, I would like it to stop. I am using the entire function with if statements to do a recursive call so sometimes it gives me errors. For some reason when I add the return it still gives me an infinite recursion but I will try it again.
Thanks~
Matt Fig
Matt Fig 2011 年 2 月 18 日
In that case I would try to post the whole code, if it is not too long, and ask for help.

サインインしてコメントする。


Matt Tearle
Matt Tearle 2011 年 2 月 18 日
Do you want that to be an error condition? In which case error('no') (in place of disp) will display the message and terminate execution.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by