rows which do not contain zero

8 ビュー (過去 30 日間)
Mate 2u
Mate 2u 2012 年 7 月 23 日
Hi all, I have a matrix D = 294x34. I want to output the number of rows which which may contain a number (so I want the the number of rows which are not all zeros).
Thank you.
  1 件のコメント
Mate 2u
Mate 2u 2012 年 7 月 23 日
I apologise, lets say for instant our D = [2,4; 5,0;4,4; 0,0; 3,0; 0,0]
output should be 4 as there were two rows full of only zeros.

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

採用された回答

Matt Kindig
Matt Kindig 2012 年 7 月 23 日
row = any(D,2);
rowCount = sum(row); %number of rows with non-zero elements

その他の回答 (2 件)

Nirmal
Nirmal 2012 年 7 月 23 日
編集済み: Nirmal 2012 年 7 月 23 日
count=sum(sum(D==0,2)==0)
count will be the number of rows which are not all zeros in matrix D.

Ryan
Ryan 2012 年 7 月 23 日
編集済み: Ryan 2012 年 7 月 23 日
row_numbers = find(sum(A,2) ~= 0);
number_of_rows = numel(row_numbers);

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by