% Function to add all current column with current row, creating an output matrice of the same dimensions, containing the sums. % Example: % Input: A = [1 2 3; 4 5 6] % B(1,1) = 1+2+3(row) + 1+4(column) = 11 % Output: B = [11, 13, 15; 20, 22, 24] function B = matsum(A) K=size(A); B = []; for c=1:K(2) % Loop through columns for d=1:K(1) % Loop through rows SumC = 0; SumR = 0; for e=1:K(2) % Add all data in current column SumC = SumC+A(d,e); end for f=1:K(1) % Add all data in current row SumR = SumR+A(f,d); end B(d,c) = SumC+SumR; end end