Generate new column from cumulating another

1 回表示 (過去 30 日間)
Lukas Netzer
Lukas Netzer 2021 年 4 月 17 日
コメント済み: Lukas Netzer 2021 年 4 月 17 日
Hey,
I am trying to cumulate the values in a table's column and generate a new column with those values. The Table has 2734 lines. I tried running this code:
for x = 0:1:2733
t.AccumulatedCapacityLow(x+1)=t.neededCapacityLow(x)+t.neededCapacityLow(x+1)
end
This is not working as array indices must be positive integers - is there a way around that?
The result should look like that:
t.nCL t.ACL
1 1
2 3
3 6
4 10
Thanks for your help!

採用された回答

Stephan
Stephan 2021 年 4 月 17 日
編集済み: Stephan 2021 年 4 月 17 日
A = (1:4)'
A(:,2) = cumsum(A)
gives:
A =
1
2
3
4
A =
1 1
2 3
3 6
4 10

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTest Model Components についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by