Duplicating columns into a matrix

90 次查看(过去 30 天)
Hi!
I think this is very easy to solve, but I simply dont know what is the easiest way. Let's say I have a vector:
A=[1 2 3]
Now I want to repeat this column into a Matrix
B=[1 2 3; 1 2 3; 1 2 3]
How do I go about this?
Thanks in advance.
Alexander

采纳的回答

Birdman
Birdman 2018-3-22
B=repmat(A,3,1)

更多回答(1 个)

Jan
Jan 2018-3-22
编辑:Jan 2018-3-22
Or:
B = A(ones(1,3), :)
This is what happens inside repmat also. It has slightly less overhead, but I'd prefer repmat instead - for unclear reasons.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by