How to create an array with first 100 elements as 1, next 100 as 2 and so on?
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Sahil Islam
 le 26 Fév 2022
  
    
    
    
    
    Commenté : Sahil Islam
 le 26 Fév 2022
            I want to create an array which looks like this:
[1 1 1 1 ...(100 time), 2 2 2 2...(100 times), 3 3 3 3....]
like this. 
I'm very new to matlab, Any help? 
2 commentaires
  Stephen23
      
      
 le 26 Fév 2022
				The simple MATLAB approach: https://www.mathworks.com/help/matlab/ref/repelem.html
Réponse acceptée
Plus de réponses (1)
  Vineet Kuruvilla
 le 26 Fév 2022
        n = 5;
A=[];
for i = 1 : 5
    A=vertcat(A,i*ones(1,100));
end
disp(A)
1 commentaire
  Vineet Kuruvilla
 le 26 Fév 2022
				
      Modifié(e) : Vineet Kuruvilla
 le 26 Fév 2022
  
			You can change vertcat to horzcat if you want all in one row.
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!



