MATLAB Answers

0

rows which do not contain zero

Asked by Mate 2u on 23 Jul 2012
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 Comment

Mate 2u on 23 Jul 2012
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.

Sign in to comment.

3 Answers

Answer by Matt Kindig on 23 Jul 2012
 Accepted Answer

row = any(D,2);
rowCount = sum(row); %number of rows with non-zero elements

  0 Comments

Sign in to comment.


Answer by Nirmal
on 23 Jul 2012
Edited by Nirmal
on 23 Jul 2012

count=sum(sum(D==0,2)==0)
count will be the number of rows which are not all zeros in matrix D.

  0 Comments

Sign in to comment.


Answer by Ryan
on 23 Jul 2012
Edited by Ryan
on 23 Jul 2012

row_numbers = find(sum(A,2) ~= 0);
number_of_rows = numel(row_numbers);

  0 Comments

Sign in to comment.