필터 지우기
필터 지우기

Summing values in a loop

조회 수: 2 (최근 30일)
James Crowe
James Crowe 2017년 10월 27일
댓글: James Crowe 2017년 10월 27일
Hi, how would I add values in a loop after iteration. eg. say values that came out were 1,2,3,4,5. I would want an array of 1,3,6,10,15. So 3rd number is first 3 added together and 5th is the first 5 etc. Thank you.
iiTerm = zeros(10,1)
for ii = 1:10
iiTerm(ii) = (((-1).^(ii-1)).*(((pi/4).^(2.*(ii-1))))./(factorial(2.*(ii-1))));
end

채택된 답변

Torsten
Torsten 2017년 10월 27일
You mean
for ii = 1:10
iiTerm(ii) = (((-1).^(ii-1)).*(((pi/4).^(2.*(ii-1))))./(factorial(2.*(ii-1))));
end
iiSum = cumsum(iiTerm);
?
Best wishes
Torsten.
  댓글 수: 1
James Crowe
James Crowe 2017년 10월 27일
Thats exactly it! thank you very much!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by