Merge two or more matrices while overlapping them

5 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Dic. de 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

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by