removing zeros element in row and colum
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi I have 200x200 of data, but it contains zeros and non-zeros element, how to remove all the zeros in the column and row?
2 comentarios
Guillaume
el 20 de Dic. de 2017
Note that a matrix can't have empty elements, so if you remove all the zeros you will have to reshape the matrix into a vector (Birdman's answer do that automatically) or replace the zeros with something else if you want to keep the 200x200 shape.
Walter Roberson
el 27 de Dic. de 2017
Are you trying to remove rows in which all of the elements of the row are 0? And to remove columns in which all of the elements of the column are 0 ?
Respuestas (1)
Akira Agata
el 27 de Dic. de 2017
As Guillaume-san mentioned, you can't have empty element in a matrix without changing the matrix shape.
But if you simply want to replace zeros in the matrix by some another value, you can do it by logical indexing technique, like:
A = eye(4); % Sample matrix with zeros
idx = A == 0; % indexing the position of zeros in the matrix
A(idx) = NaN; % Replace zeros by NaN
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!