Given the matrix:
A = [1 2 3; 4 5 6; 7 8 9];
Another answer for the first question is to use one for loop and perform linear indexing into the array using the function NUMEL to get the total number of elements:
total = 0; for i = 1:numel(A) total = total+A(i); end