replicate values of a vector

Dear all,
I have, say the vector A=(1:12)'; and I want to replicate each of the 12 numbers 4 times. Any simple code for this?
thanks in advance

 Respuesta aceptada

Friedrich
Friedrich el 23 de Mayo de 2012

0 votos

Hi,
try repmat:
repmat(A,4,1)
Or for the other direction:
repmat(A,1,4)
In the case you want it repeated like this: [1 1 1 1 2 2 2 2 ....] you can use repmat and reshape:
reshape(repmat(A,4,1),[],1)

2 comentarios

antonet
antonet el 23 de Mayo de 2012
thank you friedrich!
Andrei Bobrov
Andrei Bobrov el 23 de Mayo de 2012
kron(A,ones(4,1))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 23 de Mayo de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by