function result = sumRowsCols(x,rc)
% FOR2 sums the numbers in x, row by row or column by column depending on
% the second argument
% x is an array, rc is 1 for column by column, 2 is for row by row
[i j ] = size(x);
if nargin==1 | rc==1 % col by col
result=zeros(1,j);
for c = 1:j
for r = 1:i
result(1,c) = result(1,c) + x(r,c);
end
end
elseif rc==2
result=zeros(i,1);
for r = 1:i
for c = 1:j
result(r,1) = result(r,1) + x(r,c);
end
end
else
result=0
end
end