a(a(a>3)<10) = OK ; a(a>3 && a<10) = wrong!, the correct way?
1 回表示 (過去 30 日間)
古いコメントを表示
a=[1 2 3 4 11 33]; I want to get the number in a from 4-9; a(a(a>3)<10) is right; a(a>3 && a<10) is wrong -- is there other correct way to make this ?
0 件のコメント
採用された回答
Alexandra Harkai
2017 年 2 月 27 日
If you want to get only values between 3 and 10 (excluding the endpoints), the correct way would be:
a(a>3 & a<10)
(Not exactly sure what you meant by 'OK' but a(a(a>3)<10) definitely gives some unexpected results.)
2 件のコメント
John D'Errico
2017 年 2 月 27 日
Note that Alexandra used a single & operator there. This is correct when you are anding together boolean vectors. Use && only in things like a test in an if statement.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!