If conditions multiple loops

3 ビュー (過去 30 日間)
Sally Sakr
Sally Sakr 2023 年 5 月 11 日
コメント済み: Sally Sakr 2023 年 5 月 12 日
Why the first loop only that is work with me ? Other loops doesn't work can I know what is the mistake ? %enter data of scan clc,clear PAs = 9; DAs = 8; As = 131; Bs = 3; if (PAs==0) (DAs==0) (As==0) (Bs==0) disp('specimen is sound'); elseif (0<PAs<10) (0<DAs<10); (As<100); (Bs<2); disp('cap undercut'); elseif (0<PAs>10) (0<DAs<10); (As>100); (Bs>2); disp('toe crack'); else disp('not identified'); end

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 5 月 11 日
編集済み: Dyuman Joshi 2023 年 5 月 11 日
Firstly, if-else condition statements are not loops.
Secondly you need to use either "&" or "|" depending upon the how you want to compare. Use "&" if you want to all conditions to be satisfied, otherwise, use "|" if you want only one of the conditions to be satisfied.
Also, you need to specify each conditional relation separately, for e.g. (a>0 &a<10) is the valid syntax.
PAs = 9;
DAs = 8;
As = 131;
Bs = 3;
%I have used & here
if (PAs==0) & (DAs==0) & (As==0) & (Bs==0)
disp('specimen is sound');
elseif (0<PAs) & (PAs<10) & (0<DAs) & (DAs<10) & (As<100) & (Bs<2);
disp('cap undercut');
elseif (0<PAs) & (PAs<10) & (0<DAs) & (DAs<10) & (As>100) & (Bs>2);
%There was a typo here^
disp('toe crack');
else disp('not identified');
end
toe crack
  1 件のコメント
Sally Sakr
Sally Sakr 2023 年 5 月 12 日
thank you very much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by