Removing zero columns from matrix
    42 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Esegboria Osarhemen
 am 10 Feb. 2019
  
    
    
    
    
    Kommentiert: Ömer BOZKURT
 am 16 Aug. 2022
            This is my code:
N=3;
x=randi(9,3,N) 
func = @(index)bsxfun(@minus,x(:,1:N),x(:,index));
mat = cell2mat(arrayfun(func,1:N,'uni',0))
This is my output:
     0    -5    -4     5     0     1     4    -1     0
     0     0    -6     0     0    -6     6     6     0
     0    -2     5     2     0     7    -5    -7     0
How do I remove columns with zeros?
0 Kommentare
Akzeptierte Antwort
  madhan ravi
      
      
 am 10 Feb. 2019
        
      Bearbeitet: Guillaume
      
      
 am 1 Apr. 2020
  
      matrix(:,any(matrix == 0))=[] % removes column if there is any zero in the column
matrix(:,all(matrix == 0))=[] % removes column if the entire column is zero
4 Kommentare
  Ömer BOZKURT
 am 16 Aug. 2022
				Hello Sir. I have a question about delete columns. I want to delete columns if columns have more than 3 zero. How can I find it? Thanks for helping.
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



