If statement multiple condition overposing

조회 수: 2 (최근 30일)
Alexandra Silva
Alexandra Silva 2019년 11월 4일
댓글: Alexandra Silva 2019년 11월 4일
Does anybody know why this is not working?
It gives me the events that are < and = to zero for the left leg but for the right leg only gives me the events that are > than 0
NoncomplianceIndex = 0;
for i = 1:length(time)
if LeftFrontLegX(i) <= 0 && RightFrontLegX(i) >= 0,NoncomplianceIndex = NoncomplianceIndex + 1; end;
end;
How do the conditions work in matlab? they cannot overlap? if one is <=0 the other one cannot be >=0
Thank you so much

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 4일
편집: KALYAN ACHARJYA 2019년 11월 4일
Does anybody know why this is not working?
NoncomplianceIndex=??? % Define may be as zero
for i=1:length(time)
if LeftFrontLegX(i)<=0 && RightFrontLegX(i)>=0
NoncomplianceIndex=NoncomplianceIndex + 1;
end
end
Same can be done without loop
  댓글 수: 1
Alexandra Silva
Alexandra Silva 2019년 11월 4일
Sorry I din't show the whole code in order to simplify

댓글을 달려면 로그인하십시오.


David Hill
David Hill 2019년 11월 4일
No need for a loop.
Noncompliance=sum(LeftFrontLegX<=0 & RightFrontLegX>=0);

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by