How to sum value in rows from the previous rows

7 ビュー (過去 30 日間)
Siti Suhaila
Siti Suhaila 2017 年 8 月 15 日
コメント済み: Siti Suhaila 2017 年 8 月 15 日
Hi everyone, How to add value from previous rows. Eg: sum[i} = 185+1 , sum{i}=186+197, sum{i}=186+197+159. until the end of the cells.

採用された回答

Aniruddha Katre
Aniruddha Katre 2017 年 8 月 15 日
If the data is stored in a cell array as shown in your image, then:
cumsum(cell2mat(B))
here B is the cell array of data.
If it is a vector then simply:
cumsum(B)
where B is the vector of data.
  3 件のコメント
Aniruddha Katre
Aniruddha Katre 2017 年 8 月 15 日
What are the contents of m? Is it the same set of values as the commulativeSum in the screenshot above?
If so, then try:
cumulativeSumMat = cumsum(cell2mat(m));
If the result has to be a cell array, then add the line:
cumulativeSum = num2cell(cumulativeSumMat);
Siti Suhaila
Siti Suhaila 2017 年 8 月 15 日
TQ..... you saved my lives...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by