How to spread out an array of integers according to it's value?
    7 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Ahsan Khan
 le 9 Juin 2014
  
    
    
    
    
    Réponse apportée : Star Strider
      
      
 le 9 Juin 2014
            Hi there, say I observe a random array of integers 1-10. x = [6 3 9 4 7 10]. how can i transform this array so each integer is stored in its integer-row value. so 6 would be stored in the 6th row, 3 in the 3rd row, 9 in the 9th row, and so on and the gaps(spaces where there is no integer would be just zero) like so: resultant X = [0 0 3 4 0 6 7 0 9 10]. any help would be appreciated.
thank you.
0 commentaires
Réponse acceptée
  Star Strider
      
      
 le 9 Juin 2014
        This works:
x = [6 3 9 4 7 10];
y = zeros(1,max(x));
y(x) = x
producing:
y =
     0     0     3     4     0     6     7    0     9    10
0 commentaires
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Creating and Concatenating Matrices 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!

