maximizing efficiency in simple commands

I have an array given by
x = [1 2 3 4];
I would like to create a matrix that looks like
M = [1 2 3 4;
1 2 3 4;
1 2 3 4;
1 2 3 4];
What's the most computationally efficient way to create M from x?

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Ag. de 2013
Editada: Azzi Abdelmalek el 20 de Ag. de 2013
x=[1 2 3 4];
M=repmat(x,4,1)

1 comentario

Equivalently but removing the error checking:
x=[1 2 3 4];
M = x([1 1 1 1],:);

Iniciar sesión para comentar.

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 20 de Ag. de 2013
Editada: Andrei Bobrov el 20 de Ag. de 2013
ones(4,1)*x
kron(ones(4,1),x)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by