I have matrix
A = [1;2;3]
How do I replicate A
four times, replicating each row four times before moving onto the next, to get
[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4]
?
I have matrix
A = [1;2;3]
How do I replicate A
four times, replicating each row four times before moving onto the next, to get
[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4]
?
In this particular instance, you could do something along the lines of
A = [1;2;3;4];
B = repmat(A',4,1);
B = B(:);
What this does is replicate A'
to create a matrix B
:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
It then converts it to a single column using B(:)
.
How about using kron? It's perfect for this.
kron(A,ones(4, 1))