If conditions multiple loops

3 visualizzazioni (ultimi 30 giorni)
Sally Sakr
Sally Sakr il 11 Mag 2023
Commentato: Sally Sakr il 12 Mag 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

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 11 Mag 2023
Modificato: Dyuman Joshi il 11 Mag 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

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by