user5916581
user5916581

Reputation: 87

Inserting matrix into another matrix with Matlab

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:

enter image description here

Upvotes: 2

Views: 612

Answers (1)

horchler
horchler

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

Related Questions