필터 지우기
필터 지우기

How can i find rows or coulmns which contain maximum zeroes?

조회 수: 2 (최근 30일)
Uet
Uet 2014년 5월 21일
댓글: Star Strider 2014년 5월 25일
Hi, I want to select rows or coulmns which contain maximum zeros? can anyone please help me how to write a script file for this.. I want to develop a simple program for Assignment method..
Reagards,
Ateeq

채택된 답변

Star Strider
Star Strider 2014년 5월 22일
This will give you the number of zeros in particular rows and columns:
M = [105 0 55 15; 15 0 25 75; 55 0 0 10; 0 0 5 0];
[zr,zc] = find(M == 0);
Z = accumarray([zr zc], 1 )
rowzeros = sum(Z,2)
colzeros = sum(Z,1)
produces:
rowzeros =
1
1
2
3
colzeros =
1 4 1 1
  댓글 수: 4
Uet
Uet 2014년 5월 25일
Thank you very much... it works perfect.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Romain
Romain 2014년 5월 21일
If you want the row and the colum with the maximum of values equal to zeros, I propose (for a 2D matrix) :
[numberOfZeroCol,colWithMaxZero] = max(sum(array == 0, 1))
[numberOfZeroRow,rowWithMaxZero] = max(sum(array == 0, 2))
but I'm not sure that's what you want.
  댓글 수: 1
Uet
Uet 2014년 5월 22일
Actually I want to find number of rows and coulumns which contain more than two zeroes as covered by color lines in given picture. Then subtract 15 (which is minimum of all uncovered numbers) from all uncovered numbers.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by