Given the matrix:
A = [1 2 3; 4 5 6; 7 8 9];
1)
total = 0; for i=1:size(A,1) for j=1:size(A,2) total = total + A(i,j); end end
2)
total = sum(A(:));