필터 지우기
필터 지우기

Checking if sides of triangle are positive and if equality rule is satisfied.

조회 수: 3 (최근 30일)
David
David 2013년 10월 2일
댓글: David 2013년 10월 2일
So, I could easily do this using multiple if statements but that seems fairly repetitive. Is there an and or operator in MATLAB so that I could say: if a <= 0 and or b <= 0 and or c <= 0 error... end
And, then do a similar thing with the equality. Sorry for the fairly simple questions, first week or so using MATLAB.

채택된 답변

Matt J
Matt J 2013년 10월 2일
if any([a,b,c]<=0)
  댓글 수: 9
Matt J
Matt J 2013년 10월 2일
편집: Matt J 2013년 10월 2일
I can't tell what it's attempting to test. That's what I meant when I said it doesn't make sense.
Aside from that, though, if you run it, you will get an error. The short-circuited logical operators "&&" and "||" only apply to scalar expressions, not vectors.
David
David 2013년 10월 2일
Gotcha. Just looked up the any()operation and I understand it now. Thanks.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 10월 2일
if a<=0 || b<=0 || c<=0
% It's bad
end
  댓글 수: 4
David
David 2013년 10월 2일
편집: David 2013년 10월 2일
Btw, the above is a genuine question, not me trying to disprove you.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by