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?

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 20 日
編集済み: Azzi Abdelmalek 2013 年 8 月 20 日

0 投票

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

1 件のコメント

Walter Roberson
Walter Roberson 2013 年 8 月 20 日
Equivalently but removing the error checking:
x=[1 2 3 4];
M = x([1 1 1 1],:);

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 8 月 20 日
編集済み: Andrei Bobrov 2013 年 8 月 20 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by