Concise way to compare/find multiple values

조회 수: 48 (최근 30일)
Jurgen
Jurgen . 2017년 12월 15일
댓글: Jurgen . 2017년 12월 15일
If I have a matrix of integers called A and want to find the mask corresponding to values 1 and 7, I currently do this:
mask = (A == 1 | A == 7);
But is there a conciser way of doing this? Something like A == [1 7]. If I have many lookups I'd need to use a for loop or maybe bsxfun. It feels like there should be some simple way I'm missing.

채택된 답변

Birdman
Birdman 2017년 12월 15일
You may try ismember function.
ismember(A,[1 7]);
  댓글 수: 1
Jurgen
Jurgen 2017년 12월 15일
I knew there was something! :D

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

추가 답변 (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