How to resize array using a mask

19 Ansichten (letzte 30 Tage)
Dubstep Dublin
Dubstep Dublin am 22 Sep. 2020
Bearbeitet: Image Analyst am 22 Sep. 2020
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?

Antworten (3)

Walter Roberson
Walter Roberson am 22 Sep. 2020
a(logical(cell2mat(mask)),:)

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

Image Analyst
Image Analyst am 22 Sep. 2020
Bearbeitet: Image Analyst am 22 Sep. 2020
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), :)

Kategorien

Mehr zu Author Block Masks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by