How can I generate a matrix with the same vector in all the lines?
41 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(3 个)
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),:)
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!