필터 지우기
필터 지우기

Checking inequality condition for each component of a vector.

조회 수: 2 (최근 30일)
mjahn
mjahn 2016년 10월 3일
답변: Fangjun Jiang 2016년 10월 3일
I think there is a bug and below is what I saw:
command: vec = [0;-5;6;1.99;-2.01;-2.001;0.5];
-0.1 < vec < 0.1
ans =
0
1
0
0
1
1
0
command: -1.9 < vec < 2.1
ans =
1
1
1
1
1
1
1
I need to apply piecewise univariate function for each component in my code. Can anyone suggest a way to get the correct result?

채택된 답변

Joe Yeh
Joe Yeh 2016년 10월 3일
Unlike Python, you can't use multiple inequality expression in MATLAB. You'll have to do this :
-0.1 < vec & vec < 0.1
-1.9 < vec & vec < 2.1

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2016년 10월 3일
To explain the result you saw, your command is equal to :
temp=-0.1 < vec;
temp < 0.1

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by