I have a problem where I have a set of numbers, eg; [3 5 9] and for each of these numbers an amount of occurences eg. [2 1 5]. Now i would like to create a vector containing these numbers the prespecified amount of times, so for the example the result would be [3 3 5 9 9 9 9 9 ]. Is there an elegant way to do this in MATLAB, that is, vectorized?
            Asked
            
        
        
            Active
            
        
            Viewed 91 times
        
    1 Answers
1
            repelem is the function you want
a = [3,5,9]; b = [2,1,5]; c = repelem(a,b)
c =
     3     3     5     9     9     9     9     9
 
    
    
        user1543042
        
- 3,422
- 1
- 17
- 31
