evaluate whether a condition is met
이전 댓글 표시
Hi all, I have to evaluate whether a condition is met: this is the basic method:
if a1 < b1 < a2
disp ('ok')
else disp ('error')
end
If I had n "b" and n+1 "a" I should write n if or is there a way to simplify it? if so how? thank you very much
댓글 수: 1
I assume you really mean
if a1 < b1 & b1 < a2
disp ('ok')
else disp ('error')
end
채택된 답변
추가 답변 (2개)
Max
2012년 11월 27일
댓글 수: 6
Max
2012년 11월 27일
is correct if I do: if a(1:end-1) < (a(1:end-1) + x(1:end) ) < a(2:end-1)
No. Triple inequality statements in MATLAB will not do what you expect. That was the point of my earlier Comment. For example, I don't think you expect the following to return false, but it does:
>> 0<.5<1
ans =
0
Contrast this with,
>> (0<.5) & (0.5<1)
ans =
1
Max
2012년 11월 28일
Matt J
2012년 11월 28일
You should post this as a new question and make it clearer. We would probably need a specific example showing the output that you want.
Max
2012년 11월 28일
카테고리
도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!