rows which do not contain zero

조회 수: 6 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by