フィルターのクリア

delete all zero columns and the same columns in another matrix

1 回表示 (過去 30 日間)
Qian cao
Qian cao 2015 年 12 月 22 日
コメント済み: Qian cao 2015 年 12 月 22 日
Hi all, I have two simplified matrixes that I need to cope with. A=[0 1 0 1;0 4 0 1; 0 3 0 0; 0 1 0 2 ]; How I delete the columns in A with all zeros please? So the deleted columns should be col 1 and 3. AND! How to delete the same columns( indexed from A?) in B=[2 1 7 1;1 4 2 1; 1 3 6 6; 0 1 6 2 ]; So, col 1 and 3 are also deleted. I know I can use indexes to make it but my function is kind of too complexed...Wish you a nice Christmas day!!!

採用された回答

Ingrid
Ingrid 2015 年 12 月 22 日
You could try something like this
zerosLocations = ~A;
idx = (sum(zerosLocations) == size(A,1));
A(:,idx) = [];
B(:,idx) = [];
  1 件のコメント
Qian cao
Qian cao 2015 年 12 月 22 日
Thank you very much. Very smart answers.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by