a(a(a>3)<10) = OK ; a(a>3 && a<10) = wrong!, the correct way?

조회 수: 1 (최근 30일)
Leotsing
Leotsing 2017년 2월 27일
편집: Leotsing 2017년 2월 27일
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 ?

채택된 답변

Alexandra Harkai
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
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.
Leotsing
Leotsing 2017년 2월 27일
편집: Leotsing 2017년 2월 27일
thank you and other people answered! that"OK" means it works well to the result,but I think it is not good,so I asked.BTW, I also thought about FIND function,but never come to "&" .thank you again!

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

추가 답변 (0개)

카테고리

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