How to write if else program on matlab?
古いコメントを表示
This is the program, but it is not working. My output is always 5. But why? How to correct it? It is written as a matlab function in simulink.
PROGRAM:
function betaref = fcn(w)
if (w<5)
betaref=45;
elseif (5<w<15)
betaref=5;
elseif (15<w<25)
betaref=0;
else
betaref=90;
end
2 件のコメント
Ameer Hamza
2020 年 3 月 19 日
Run
value = fcn(0);
It returns 45 on my system,
Drishya Dinesh
2020 年 3 月 19 日
編集済み: Drishya Dinesh
2020 年 3 月 19 日
回答 (1 件)
Steven Lord
2020 年 3 月 19 日
elseif (0<power<=1000)
This doesn't do what you think it does. If you're writing this code in the MATLAB Editor and you're using a relatively recent release you should have received a Code Analyzer warning alerting you to that fact (an orange line in the right scroll bar for the Editor window and orange underlines of part of this construct.)
Instead:
elseif (0<power & power<=1000)
カテゴリ
ヘルプ センター および File Exchange で Seismology についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!