필터 지우기
필터 지우기

How to use cumsum for single column matrix non integer values

조회 수: 1 (최근 30일)
Charlie Hillary
Charlie Hillary 2020년 12월 2일
댓글: Charlie Hillary 2020년 12월 2일
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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 2일
편집: Ameer Hamza 2020년 12월 2일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by