How to Create array with repeating values of another array

Hi I have an array say x = [1 2 3 4 5] generated from previous code. I want to then create an array y = [1 1 2 2 3 3 4 4 5 5] what is the easiest way to accomplish this?

Respuestas (2)

Hi David,
use repmat and linear indexing:
x = [1 2 3 4 5];
% repeat two times:
xx = repmat(x, 2, 1);
% and access all elements
xRep = xx(:)'
xRep =
1 1 2 2 3 3 4 4 5 5
Titus

Categorías

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

Etiquetas

Preguntada:

el 28 de En. de 2016

Comentada:

el 28 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by