Summation of two matrices
3 views (last 30 days)
Show older comments
Hi guys,
I really need your help with the summation of matrices in Matlab.
I have two matrices (180,360), which counts a total of 129 600 values, with different numbers. I would like to sum all the elements within this two matrices as follows:
- value from the 1st row and 1st coloumn of the 1st matrix sum with the value from the 1st row and 1st coloumn of the 2nd matrix,
- value from the 1st row and 2nd coloumn of the 1st matrix sum with the value of from the 1st row and 2nd coloum of the 2nd matrix,
- and so on until the end.
I tried to do next:
Z = A + B and I get only one value in the last row and last coloumn. All the others values are zero (0) even the values in the both matrices are NOT zero (0). I also tried to use funtion SUM like Z = sum (A + B) but I got the result equel to 2 x Z in the last row and last coloumn.
Is there any other (easy) trick to sum this matrices?
Thank you in advance.
4 Comments
Dave B
on 13 Nov 2021
Edited: Dave B
on 13 Nov 2021
Maybe I didn't understand the problem. one of these matrices has a bunch of zeros on the sides and a bunch of values in the middle, the other has the opposite pattern. They have one column where they overlap. When I add them I see their summed values
load Izb_hv_p
load Izb_hv_bl
Z=Izb_hv_bl+Izb_hv_p;
% Look at some random rows/columns:
for i = 1:10
r=randi(180);
c=randi(360);
fprintf('Izb_hv_p: %0.2f + Izb_hv_bl: %0.2f = Z: %0.2f\n', Izb_hv_p(r,c), Izb_hv_bl(r,c), Z(r,c))
end
% Visualize the whole thing as an image:
t=tiledlayout(3,2);
nexttile
imagesc(Izb_hv_bl)
title('Izb_hv_bl','Interpreter','none')
nexttile
imagesc(Izb_hv_p)
title('Izb_hv_p','Interpreter','none')
nexttile([2 2])
imagesc(Z)
title('Z')
set(t.Children,'CLim',[0 max(Z,[],'all')])
colormap turbo
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!