removing zeros element in row and colum

7 visualizzazioni (ultimi 30 giorni)
Alya Z
Alya Z il 20 Dic 2017
Commentato: Walter Roberson il 27 Dic 2017
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 Commenti
Guillaume
Guillaume il 20 Dic 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
Walter Roberson il 27 Dic 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 ?

Accedi per commentare.

Risposte (1)

Akira Agata
Akira Agata il 27 Dic 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

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by