Extraction of non zero rows from a matrix

26 ビュー (過去 30 日間)
Satinath Debnath
Satinath Debnath 2021 年 11 月 3 日
コメント済み: Satinath Debnath 2021 年 11 月 3 日
I have a 12x3 matrix data in each of my measurement epoch. Sometimes, some of the rows are zero indicating no data in the channel. So, I want to extract only those rows without zero. I am using matlab find and index operator but it gives me the column vector instead of rows. How can I extract non-zero rows using simple index operator and without any loop. Any help would be appreciated. I have attached the snapshots of my work so far.

採用された回答

Chris
Chris 2021 年 11 月 3 日
編集済み: Chris 2021 年 11 月 3 日
A = [magic(3);zeros(1,3)]
A = 4×3
8 1 6 3 5 7 4 9 2 0 0 0
svp = A~=0
svp = 4×3 logical array
1 1 1 1 1 1 1 1 1 0 0 0
extracted = reshape(A(svp),[],3)
extracted = 3×3
8 1 6 3 5 7 4 9 2
If there is a possibiity of finding zeros in a nonzerow row, you would want to do something like this:
extracted = A(~prod(A==0,2),:)
extracted = 3×3
8 1 6 3 5 7 4 9 2
  3 件のコメント
Chris
Chris 2021 年 11 月 3 日
編集済み: Chris 2021 年 11 月 3 日
I just noticed that both our solutions don't allow for zeros in a nonzero row. I've posted a more correct solution at the end of my answer.
Satinath Debnath
Satinath Debnath 2021 年 11 月 3 日
@Chris. OKay. Thank you.

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

その他の回答 (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