replicate values of a vector

2 vues (au cours des 30 derniers jours)
antonet
antonet le 23 Mai 2012
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

Réponse acceptée

Friedrich
Friedrich le 23 Mai 2012
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 commentaires
antonet
antonet le 23 Mai 2012
thank you friedrich!
Andrei Bobrov
Andrei Bobrov le 23 Mai 2012
kron(A,ones(4,1))

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by