Hi all,
I have an array 48X365, where some of the columns are zero!
Is there any way to delete them and get an array without these columns?
The thing is that the columns appear randomly
thanks!

 Respuesta aceptada

Guillaume
Guillaume el 4 de Abr. de 2017

2 votos

if you want to delete columns with all 0:
yourmatrix(:, all(yourmatrix == 0)) = [];
if you want to delte columns with any 0:
yourmatrix(:, any(yourmatrix == 0)) = [];

Más respuestas (1)

KSSV
KSSV el 4 de Abr. de 2017

0 votos

Let data be your matrix where few columns are zeroes. Use:
data(:, sum(data,1)==0) = [] ; % removes columns with zeroes

2 comentarios

Stephen23
Stephen23 el 4 de Abr. de 2017
Buggy code: if the column contains [-1;1], then this code would incorrectly identify it and remove it.
Guillaume's answer is the correct way to do this.
KSSV
KSSV el 4 de Abr. de 2017
Yes....it flashed me now...

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 4 de Abr. de 2017

Comentada:

el 4 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by