MATLAB Answers

sum of elements of an array

1 ビュー (過去 30 日間)
RAFFAELE CANTERI
RAFFAELE CANTERI 2021 年 2 月 26 日
コメント済み: RAFFAELE CANTERI 2021 年 2 月 26 日
I'm sorry for the stupid question, but If i have an array A = [1,2,5,7,9] and i want an array B = [1,3,8,15,24], progressive sum of the elemts in A, what is the code that returns me B? Thanks!

回答 (1 件)

John D'Errico
John D'Errico 2021 年 2 月 26 日
編集済み: John D'Errico 2021 年 2 月 26 日
B = cumsum(A);
You could have learned about this function by reading the help for sum. At the bottom of the help, you would see a see also line. That reads:
See also prod, cumsum, diff, accumarray, isfloat.
  1 件のコメント
RAFFAELE CANTERI
RAFFAELE CANTERI 2021 年 2 月 26 日
Easy! Thanks

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by