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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by