フィルターのクリア

How can I generate a matrix with the same vector in all the lines?

43 ビュー (過去 30 日間)
Lorenz
Lorenz 2012 年 11 月 13 日
Hello,
I'd like to generate a matrix with the same vector n times. What I can choose. For example:
A= [ 1 2 3; 1 2 3; 1 2 3; .....n times......; 1 2 3]
Thank You

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 11 月 13 日
A = repmat(1:3,n,1)
And to learn more:
doc repmat

その他の回答 (3 件)

Evan
Evan 2012 年 11 月 13 日
編集済み: Evan 2012 年 11 月 13 日
Another option:
V = [1:3];
n = 4; % desired number of rows
M = ones(n,1) * V
Returns
M = [1 2 3
1 2 3
1 2 3
1 2 3]

Matt Fig
Matt Fig 2012 年 11 月 13 日
I think this is what REPMAT probably is doing behind the scenes:
V = 1:3;
M = V(ones(1,4),:)

Walter Roberson
Walter Roberson 2012 年 11 月 13 日
t = 1:3;
A = t(ones(n,1), :); %what repmat will do internally so faster than repmat
or
kron(1:3, ones(n,1)); %slower than repmat but kron() has some good uses

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by