How to sum value in rows from the previous rows

조회 수: 10 (최근 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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by