If Else statement problem

if(P1>=P1min)&(P1<=P1max)
fprintf 'Machine 1 is in limits'
*elseif*
(P2>=P2min)&(P2<=P2max)
fprintf 'Machine 2 is in limits'
else
P1=P1max
P2=pd-(P1max+P3min)
P3=P3min
end
end
end
What is the error in ELSE IF statement. matlab gives me this error
"Expression or statement is incomplete or incorrect."

回答 (1 件)

KL
KL 2017 年 10 月 22 日
編集済み: KL 2017 年 10 月 22 日

0 投票

The syntax is very simple,
if (P1>=P1min) && (P1<=P1max)
fprintf 'Machine 1 is in limits'
elseif (P2>=P2min) && (P2<=P2max)
fprintf 'Machine 2 is in limits'
else
P1=P1max
P2=pd-(P1max+P3min)
P3=P3min
end
you only need one 'end'.

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2017 年 10 月 22 日

編集済み:

KL
2017 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by