필터 지우기
필터 지우기

Adding all previous to create a new row

조회 수: 4 (최근 30일)
Hendrik
Hendrik 2012년 12월 11일
Hello, if i have a row, I want to create a new row, where the first number is the same, the second number is the first and second from previous row. The third number is the first plus the second plus the third from the first row.
for example: x=[10 9 8 7 6 5] then i want the new row to become: y = [10 19 27 34 40 45]
The best I could come up with was:
y=[x]+[0,x(1:end-1)]+[0 0,x(1:end-2)]+....+[0 0 0 0 0,x(1:end-5)]
But there has to be an easier wawy, since this only works for short rows

채택된 답변

Honglei Chen
Honglei Chen 2012년 12월 11일
편집: Honglei Chen 2012년 12월 11일
You can use cumsum
y = cumsum(x)
You can also do
filter(ones(1,numel(x)),1,x)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by