grouping values of 3 columns
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Mohamuud hassan
 il 8 Mag 2015
  
    
    
    
    
    Risposto: Michael Haderlein
      
 il 8 Mag 2015
            hello all, i have one question which is related to grouping columns. for instance:
data=[2 0 2; 0 0 0; 0 2 0; 0 0 12];
what i want are
202 as one row and one col
000 as one row and one col
020 as one row and one col
0012 as one row and one col
0 Commenti
Risposta accettata
  Michael Haderlein
      
 il 8 Mag 2015
        Not clear what you mean: Do you want a numeric array or a string? If it's numeric, there's no 020 but only 20. If you want string, you'll have to use cells. One possibility is:
cellfun(@(c)sprintf('%d',c),mat2cell(data,ones(size(data,1),1),size(data,2)),'uniform',false)
ans = 
      '202'
      '000'
      '020'
      '0012'
If it's still numeric, you could do this:
sum(bsxfun(@times,data,10.^(size(data,2)-1:-1:0)),2)
ans =
     202
       0
      20
      12
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Data Type Conversion 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!

