Merge two or more matrices while overlapping them

5 Ansichten (letzte 30 Tage)
Sudip Karmacharya
Sudip Karmacharya am 9 Dez. 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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Dez. 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

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by