Borrar filtros
Borrar filtros

Populate Array with duplicate variables

1 visualización (últimos 30 días)
Uchenna
Uchenna el 18 de Sept. de 2013
Hi,
I am trying to duplicate the elements within a Matlab array according to the position of elements of the array.
For instance,
x = [1,2,3,4,5,6,4,2,7,5,3] should become x1 = [1,1,2,2,3,3,4,4,5,5,6,6,4,4,2,2,7,7,5,5,3,3]
Thanks

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 18 de Sept. de 2013
Editada: Azzi Abdelmalek el 18 de Sept. de 2013
x = [1,2,3,4,5,6,4,2,7,5,3]
y=[x;x]
y=y(:)'
%Or
n=2
x=repmat(x,n,1);
y=y(:)'

Más respuestas (1)

Jos (10584)
Jos (10584) el 19 de Sept. de 2013
Another ML-trick:
% data
x = [1 4 3 6] ;
n = 2 ;
% engine
y = kron(x,ones(1,n))

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by