Merge two or more matrices while overlapping them
5 views (last 30 days)
Show older comments
Sudip Karmacharya
on 9 Dec 2020
Commented: Sudip Karmacharya
on 9 Dec 2020
I want to merge two matrices like shown below. Where, overlapping cells are added together to create a bigger matrix.
The columns and rows of A and B, have a differnent "global ID". When they are combined together, whichever cells have overlapping ID, are summed up.

0 Comments
Accepted Answer
Image Analyst
on 9 Dec 2020
Assuming they're double arrays rather than cell arrays, try this:
A = [a, b; c, d]
B = [1, 2; 3, 4];
D = zeros(3, 3);
D(1:2, 1:2) = A; % Put A in
% Now add in B
D(2:end, 2:end) = D(2:end, 2:end) + B
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!