MATLAB: How to create every sum of column entries of a m x n matrix

columnforfunctionloopmatrixrecursivesum

I would like to create the sums of a mxn matrix that have m summands, one of each row – using a for loop to generate every possible combination. For my 3×3 Matrix A my code would look like this:
for i=1:3
for j=1:3
for k=1:3
S=A(1,i)+A(2,j)+A(3,k);
end
end
end
Now I need this to work for any mxn Matrix. How? Do I need a recursive function or is there any other way?

Best Answer

Figured another way:
close
clear
clc
A = [1 2 3; 4 5 6;7 8 9];
[Zeile,Spalte] = size(A);
S=MatAdd(A,1);
with
function [Summe] = MatAdd(A,aktuelleZeile)
Summe=[];
[AnzahlZeilen,AnzahlSpalten] = size(A);
if aktuelleZeile==AnzahlZeilen
Summe=A(aktuelleZeile,:)';
else
Summanden=MatAdd(A,aktuelleZeile+1);
for i=1:AnzahlSpalten
Summe=[Summe;Summanden+A(aktuelleZeile,i);];
end
end
end