what changes can be made in the code?

조회 수: 1 (최근 30일)
Manav Divekar
Manav Divekar 2021년 12월 7일
댓글: Jon 2021년 12월 7일
if input : mycumsum( [ 3 2 10 ] ) and i want is the vector sum of sum of 1st and second and so on eg [ 3 5 15 ]
function [out] = mycumsum (m)
add = 0;
for i = 1:length(m)
for j = 1:length(m)+1
a = i(m);
%b = ;
end
end
out = add;
  댓글 수: 1
Jon
Jon 2021년 12월 7일
MATLAB's cumsum will do this for you. Is this a programming excercise where you have to write your own code to do provide a cumulative sum?

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
David Hill 2021년 12월 7일
function out = mycumsum (m)
out = m(1);
for i = 2:length(m)
out(i)=out(i-1)+m(i);
end

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by