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?

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 20 Aug. 2013
Bearbeitet: Azzi Abdelmalek am 20 Aug. 2013

0 Stimmen

x=[1 2 3 4];
M=repmat(x,4,1)

1 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 20 Aug. 2013
Bearbeitet: Andrei Bobrov am 20 Aug. 2013

0 Stimmen

ones(4,1)*x
kron(ones(4,1),x)

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by