Repeat matrix element of a given matrix

my matrix is x=[2 5 3 6 1]
I want it to make it as y=[2 2 2 2 5 5 5 5 3 3 3 3 6 6 6 6 1 1 1 1]
which function does it?

1 comentario

Jan
Jan el 11 de Mzo. de 2015
This topic is discussed such frequently, that I miss it in the FAQ.

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 11 de Mzo. de 2015
Editada: Jan el 11 de Mzo. de 2015
x = [2 5 3 6 1];
y = reshape(repmat(x, 4, 1), 1, []);
Or:
y = kron(x, ones(1, 4));

3 comentarios

Nikhil Chourasia
Nikhil Chourasia el 11 de Mzo. de 2015
Thank you Jan Simon
Nikhil Chourasia
Nikhil Chourasia el 13 de Mzo. de 2015
Hi Jan Simon can you help me to regain x from y. I have used kron in my coding.
That would be
x = y(1:4:end);
This is basic matrix indexing.
In the future, start a new question rather than asking in comments.

Iniciar sesión para comentar.

Más respuestas (3)

Stephen23
Stephen23 el 11 de Mzo. de 2015
Editada: Stephen23 el 11 de Mzo. de 2015
Another quick one-liner:
reshape(ones(4,1)*x,1,[])

2 comentarios

Nikhil Chourasia
Nikhil Chourasia el 11 de Mzo. de 2015
Thank you Stephen Cobeldick
Nikhil Chourasia
Nikhil Chourasia el 13 de Mzo. de 2015
Hi Stephen Cobeldick can you help me to regain original matrix

Iniciar sesión para comentar.

Guillaume
Guillaume el 11 de Mzo. de 2015
New in 2015a, repelem:
repelem(x, 4)
Andrei Bobrov
Andrei Bobrov el 11 de Mzo. de 2015
x = [2 5 3 6 1];
y = x(ceil((1:4*numel(x))/4));

3 comentarios

Nikhil Chourasia
Nikhil Chourasia el 11 de Mzo. de 2015
Thank You Andrei Bobrov
Nikhil Chourasia
Nikhil Chourasia el 13 de Mzo. de 2015
Hi Andrei Bobrov can you help me to regain x from y
x = unique(y);

Iniciar sesión para comentar.

Preguntada:

el 11 de Mzo. de 2015

Comentada:

el 13 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by