-1

Let's say I have this array:

1 2 3 4

and I want to create an array like this:

1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4

How could I create that?

Andrew Zaw
  • 754
  • 1
  • 9
  • 16

1 Answers1

0

From the documentation for repelem:

repelem Replicate elements of an array. U = repelem(V,N), where V is a vector, returns a vector of repeated elements of V.

So what you want is:

>> repelem([1 2 3 4],4)
Martin Dinov
  • 8,757
  • 3
  • 29
  • 41