If you think about how basic matrix, vector multiplication works, you can see that you can sum rows of a matrix by multiplying by a column vector of ones. You can sum selected elements of a column vector by premultplying by a row vector consisting of zeros and ones (with zeros for the elements that you don't want to include in the sum). Putting these ideas together in your case gives
You could also accomplish what you want using MATLAB's indexing abilities along with the sum function. Note that A(1,:) means row 1, every column of A. Similarly A(3,:) means row 3 every column of A
y = sum(A(1,:)) + sum(A(3,:))
Best Answer