Filter löschen
Filter löschen

Checking inequality condition for each component of a vector.

2 Ansichten (letzte 30 Tage)
mjahn
mjahn am 3 Okt. 2016
Beantwortet: Fangjun Jiang am 3 Okt. 2016
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?

Akzeptierte Antwort

Joe Yeh
Joe Yeh am 3 Okt. 2016
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

Weitere Antworten (1)

Fangjun Jiang
Fangjun Jiang am 3 Okt. 2016
To explain the result you saw, your command is equal to :
temp=-0.1 < vec;
temp < 0.1

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by