Reputation: 87
I want to put a small matrix (p-by-q) called B
into a bigger matrix (m-by-n) called A
. How can I do it? Matrix B
should be put on the right corner of matrix A
:
Upvotes: 2
Views: 612
Reputation: 18484
You can do this with basic array indexing, for example:
m = 3;
n = 4;
A = rand(m,n)
p = 2;
q = 3;
B = rand(p,q)
A(end-p+1:end,end-q+1:end) = B
... assuming that p <= m and q <= n of course.
Upvotes: 4