This question already has an answer here:
Hey I would like to do something like the following
A = [...
1 2 3
4 5 6
7 8 9]
to
B = [...
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6
7 8 9
7 8 9
7 8 9]
But please do not advice manual things. I am writing an algorithm with inputs and matrix dimensions may change.
You can also try something based on the following:
d
ande
both result in the matrix below:To append more rows you can also use this for loop and see what the result is:
There's a few ways. The simplest I think would be to use the Kronecker product:
the faster but less readable solution is replication by multiplication and reshaping:
or the same solution, but then using
repmat
: