rows which do not contain zero

6 vues (au cours des 30 derniers jours)
Mate 2u
Mate 2u le 23 Juil 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 commentaire
Mate 2u
Mate 2u le 23 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (2)

Nirmal
Nirmal le 23 Juil 2012
Modifié(e) : Nirmal le 23 Juil 2012
count=sum(sum(D==0,2)==0)
count will be the number of rows which are not all zeros in matrix D.

Ryan
Ryan le 23 Juil 2012
Modifié(e) : Ryan le 23 Juil 2012
row_numbers = find(sum(A,2) ~= 0);
number_of_rows = numel(row_numbers);

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by