How can i find rows or coulmns which contain maximum zeroes?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Uet
el 21 de Mayo de 2014
Comentada: Star Strider
el 25 de Mayo de 2014
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163118/image.jpeg)
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
0 comentarios
Respuesta aceptada
Star Strider
el 22 de Mayo de 2014
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 comentarios
Más respuestas (1)
Romain
el 21 de Mayo de 2014
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.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!