How to end function when condition is met
古いコメントを表示
I havent used Matlab for a while and was never really good at it. I need your help
How to terminate the function, as soon as NL reaches the number 1?
I think i have to put the 'if' and 'return' above the function but then Matlab tells me, that it doesnt know NL yet.
What am I doing wrong?
function NL = NLDestillationsblase(x, x0, Omega1)
NL = (x/x0).^(1./(Omega1-1)).*((1-x0)./(1-x)).^(Omega1./(Omega1-1))
if NL >= 1
return
end
end
4 件のコメント
Walter Roberson
2020 年 11 月 9 日
編集済み: Walter Roberson
2020 年 11 月 9 日
return is fine for this purpose. There is no obvious error in your code... though clearly you would be wanting to loop.
Generally speaking if you are looping, it is cleaner to break the loop and just let the code reach the end of the function instead of returning.
Marcel Langner
2020 年 11 月 9 日
David Hill
2020 年 11 月 9 日
That is because x is an array.
function NL = NLDestillationsblase(x, x0, Omega1)
NL = (x/x0).^(1./(Omega1-1)).*((1-x0)./(1-x)).^(Omega1./(Omega1-1))
NL=NL(NL<1);
end
Marcel Langner
2020 年 11 月 9 日
編集済み: Marcel Langner
2020 年 11 月 9 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!