0

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?

BDP1
  • 23
  • 4
  • here's another http://stackoverflow.com/q/2382319/97160, and probably many more questions – Amro Mar 27 '16 at 17:20

1 Answers1

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