Azzera filtri
Azzera filtri

How to use cumsum for single column matrix non integer values

1 visualizzazione (ultimi 30 giorni)
Hi,
I have this single column array
km =
48.8236
26.0224
207.8332
182.5684
186.1395
184.3869
183.3776
189.1579
188.4118
186.5033
93.2608
338.8983
304.3481
181.5408
173.1552
114.0832
149.5733
148.9748
147.1931
132.4991
97.0483
35.4943
22.2470
174.0249
47.2259
47.0986
251.9559
126.3655
254.0408
134.7754
display (km)
I have tried this code but get this error:
cs = cumsum(km,1)
display(cs)
"Index in position 1 is invalid. Array indices must be positive integers or logical values" - error is in cs = cumsum(km,1).
How would like to add each previous value to the next one and so on, like so:
km =
48.8236
26.0224
207.8332
182.5684
goes to:
km =
48.8236
78.8460
282.6972
465.2476

Risposta accettata

Ameer Hamza
Ameer Hamza il 2 Dic 2020
Modificato: Ameer Hamza il 2 Dic 2020
It seems that you have somewhere defined a variable name 'cumsum', which confuses MATLAB by shadowing the built-in function named cumsum(). Remove this variable
clear cumsum
cs = cumsum(km); % cs = cumsum(km,1); 1 is optional here

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by