How to filter a binary matrix through a binary vector?

4 ビュー (過去 30 日間)
Dipie11
Dipie11 2018 年 8 月 30 日
コメント済み: Dipie11 2018 年 8 月 30 日
Say I have a binary vector E and a binary matrix S,
E = [0 1 1 0 0]
S = [1 1 0 1 0; 1 1 1 1 1; 1 0 0 1 1]
I'm looking to find a matrix S_E that 'filters' the matrix S through the vector E, such that the new filtered matrix S_E only contains the placeholder values of the matrix S where there are 1's in the matrix E. So the matrix S_E would look like,
S_E = [1 0 ; 1 1 ; 0 0]
Is there any way to implement this?? Any help would be greatly appreciated.
Thanks!

採用された回答

Rik
Rik 2018 年 8 月 30 日
編集済み: Rik 2018 年 8 月 30 日
Here are two ways to do this:
E = [0 1 1 0 0];
S = [1 1 0 1 0; 1 1 1 1 1; 1 0 0 1 1];
S_E=S(:,logical(E));
E = [0 1 1 0 0];
S = [1 1 0 1 0; 1 1 1 1 1; 1 0 0 1 1];
E_expanded=repmat(logical(E),size(S,1),1);
S_E=reshape(S(E_expanded),[],sum(E));
  1 件のコメント
Dipie11
Dipie11 2018 年 8 月 30 日
Unreal man thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by