MATLAB: Sum every i-th column in matrix seperately

sum

Hi all,
I have randomly generated matrix and I want to go through all columns and to sum every i-th column separately. I don't want to sum all the columns but to sum depending on the counter in for loop for example:
[a,b] = size(C);
for i = 1:b
S = sum(C(:,i))
S = 0 %but this doesn't work, result is sum of elements of all columns

Best Answer

Try sum(A(:,[1 4]))
where A is your random matrix.The line above will give you the sums of column 1 and 4.
ex: A=spiral(4)
sum(A(:,[1 4]))
ans = 34 46