How to mask cells of certain values?

조회 수: 17 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2018년 9월 23일
편집: Rightia Rollmann 2018년 9월 24일
The following works well:
A = [1 2 3 4 5];
A > 2
0 0 1 1 1
But, how can i mask A==1 and A ==3, so getting the following result (for example putting the values that are to be masked in a vector):
mask_array = [1 2];
A ~= mask_array
0 1 0 1 1

채택된 답변

Image Analyst
Image Analyst 2018년 9월 23일
편집: Image Analyst 2018년 9월 23일
Try this:
mask = (A == 1) | (A == 3) % 1 for either 1 or 3
Or maybe you mean
mask = (A == 1) | (A >= 3) % 1 for 1 or anything 3 or more.
  댓글 수: 1
Rightia Rollmann
Rightia Rollmann 2018년 9월 24일
편집: Rightia Rollmann 2018년 9월 24일
Thanks! I meant the first solution. Is there a more compact way to write this code? (There are a large number of values that should be masked and it would be more convenient to write something like below)
OR(A == 1,3,...)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by