All pastes #363204 Raw Edit

Stuff

public c v1 · immutable
·published 2007-02-19 07:51 UTC
rendered paste body
% 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(e,d);      end      for f=1:K(1) % Add all data in current row         SumR = SumR+A(c,f);      end      B(d,c) = SumC+SumR;   endend