If conditions multiple loops

3 views (last 30 days)
Sally Sakr
Sally Sakr on 11 May 2023
Commented: Sally Sakr on 12 May 2023
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

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 11 May 2023
Edited: Dyuman Joshi on 11 May 2023
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

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!