Deleting rows of an array
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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!
0 commentaires
Réponse acceptée
  Guillaume
      
      
 le 4 Avr 2017
        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)) = [];
0 commentaires
Plus de réponses (1)
  KSSV
      
      
 le 4 Avr 2017
        Let data be your matrix where few columns are zeroes. Use:
data(:, sum(data,1)==0) = [] ;  % removes columns with zeroes
2 commentaires
  Stephen23
      
      
 le 4 Avr 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.
Voir également
Catégories
				En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


