matrix repetition

Hello,
I have a matrix M of dimensions (m by n). I want to repeat this matrix 'k' number of times along the column.
For example:
If
M=[1 3 4 5;4 5 6 7;9 3 4 2]
and k=4(say),then
out=[1 3 4 5 1 3 4 5 1 3 4 5 1 3 4 5;4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7;9 3 4 2 9 3 4 2 9 3 4 2 9 3 4 2]
please help.

1 comentario

Andrei Bobrov
Andrei Bobrov el 9 de En. de 2012
reshape(M(:,:,ones(k,1)),size(M,1),[])

Iniciar sesión para comentar.

 Respuesta aceptada

Rick Rosson
Rick Rosson el 9 de En. de 2012

1 voto

out = repmat(M,1,k);

Más respuestas (1)

Walter Roberson
Walter Roberson el 9 de En. de 2012

1 voto

repmat(M, 1, 4)
(Note: your example only uses 3 repetitions for the first row)

1 comentario

zozo
zozo el 9 de En. de 2012
sorry..it shud be 4. dats my mistake.
thanks! :)

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 9 de En. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by