If conditions multiple loops

3 次查看(过去 30 天)
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