if else if statement problem
1 回表示 (過去 30 日間)
古いコメントを表示
Please help me if you can. I wrote this but the answer still gives me the final condition only "not identified". What is the mistake ?
for PAs = 9
DAs = 8;
As = 131;
Bs = 3;
if PAs==0
DAs==0;
As==0;
Bs==0;
disp('specimen is sound')
elseif PAs==0:10
DAs==0:10;
As<100;
Bs<2;
disp('cap undercut')
else
disp('not identified')
end
end
0 件のコメント
回答 (1 件)
Cris LaPierre
2023 年 5 月 12 日
The following conditional is seen as 'false' by the elseif statement.
elseif PAs==0:10
This will check PAs against every number in 0:10. It will only evaluate true (and execute the corresponding statement) if all conditions evalue 'true'
PAs=9;
PAs==0:10
If you want the elseif statement to execute if any of the comparisons is true, use any
any(PAs==0:10)
1 件のコメント
Atsushi Ueno
2023 年 5 月 12 日
移動済み: Atsushi Ueno
2023 年 5 月 12 日
PAs = 9;
PAs == 0:10
if PAs == 0:10
disp('identified')
else
disp('not identified')
end
if any(PAs == 0:10)
disp('identified')
else
disp('not identified')
end
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!