Effacer les filtres
Effacer les filtres

Adding values of each row

1 vue (au cours des 30 derniers jours)
Ke Yeun Yong
Ke Yeun Yong le 19 Oct 2023
Modifié(e) : Voss le 19 Oct 2023
Hi, I am trying to add values on each row, for example, I have 53X1 data, I want to add 1st row value to 2nd row value, so that my 2nd row value is the added value, and this continue until the last value. May I know how to code that?
Row : Value
1 : 1
2 : 3
3 : 6
4 : 8
I want it to become
Row : Value
1 : 1
2 : (3+1 = 4)
3 : (4+6 = 10)
4 : (8 + 10 = 18)
thank you very much

Réponse acceptée

Voss
Voss le 19 Oct 2023
Modifié(e) : Voss le 19 Oct 2023
data = [1;3;6;8]
data = 4×1
1 3 6 8
result = cumsum(data,1)
result = 4×1
1 4 10 18
Or, if you want to overwrite your data with the new value:
data = cumsum(data,1)
data = 4×1
1 4 10 18

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by