How to resize array using a mask

5 ビュー (過去 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 Center および File ExchangeAuthor Block Masks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by