필터 지우기
필터 지우기

How to resize array using a mask

조회 수: 6 (최근 30일)
Dubstep Dublin
Dubstep Dublin 2020년 9월 22일
편집: Image Analyst 2020년 9월 22일
I have got an array a = { 1 , 2 , 3 ; 4 , 5 , 6 ; 7 , 8 , 9 }
also have a mask, mask = { 1 ; 0 ; 1 }
If I do a*mask, I want the resulting array = { 1 , 2 , 3 ; 7 , 8 , 9 }
Any suggestions on how to implement this?

답변 (3개)

Walter Roberson
Walter Roberson 2020년 9월 22일
a(logical(cell2mat(mask)),:)

Ameer Hamza
Ameer Hamza 2020년 9월 22일
a = [1 , 2 , 3 ; 4 , 5 , 6 ; 7 , 8 , 9];
b = [ 1; 0; 1];
c = a(b==1, :);

Image Analyst
Image Analyst 2020년 9월 22일
편집: Image Analyst 2020년 9월 22일
Assuming you're using double arrays...(since I see no need for you to be using cell arrays).
a = [1, 2, 3; 4, 5, 6; 7, 8, 9]
mask = [1; 0; 1]
masked_a = a(logical(mask), :)

카테고리

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