function [v,w]=hw2_1_13(A) % input: A is a 4x5 matrix (actually the size doesn't matter) % output: v and w are row vectors containing the colmun sums of A % get the size of A and initialize v [m,n]=size(A); v=zeros(1,n); % usually use i for rows, j for columns (r and c are good loop variables to) for j=1:n for i=1:m v(j)=v(j)+A(i,j); end end v % now use the sum function, call the 1x5 row vector w this time w=sum(A)