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

조회 수: 5 (최근 30일)
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.

채택된 답변

Walter Roberson
Walter Roberson 2013년 10월 8일
t = cumsum(A(:));
s = t(end);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by