0

i have an array in matlab software like this:

X=[x1,x2,x3];

And, I want to change this array to be like this:

X=[x1,x1,x2,x2,x3,x3];

Is there any command for doing this work in the simplest way ?

perror
  • 7,071
  • 16
  • 58
  • 85
  • You have to be more precise. Is the size of the initial array fixed ? Do you want to copy each element just once or multiple times ? – Ratbert Aug 24 '15 at 07:02

1 Answers1

0

Use reshape and repmat like this

a=[1 2 3];reshape(repmat(a, 2, 1), 1, [])

repmat creates the amount of entries and reshape orders it as you asked.

rst
  • 2,510
  • 4
  • 21
  • 47