I am trying to implement this function so that it returns the sum of all the values in the m-by-n matrix A without using the buit in function sum

1 view (last 30 days)
function s = totalsum(A)
%A is an m-by-n matrix
%s is the sum of all the values in A
I dont know where to start.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Oct 2013
t = cumsum(A(:));
s = t(end);

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!