Adding elements of a vector in matlab

조회 수: 2 (최근 30일)
ektor
ektor 2020년 5월 28일
댓글: Walter Roberson 2020년 5월 28일
Hi all,
I have a vector
a=[1 2 3 4 5 6 7 8 9 10 ];
and I want to get the vector
b=[1 +2+3+4+5+6+7 +8 +9 +10; 2+3+4+5+6+7 +8 +9 +10; 3+4+5+6+7 +8 +9 +10; 4+5+6+7 +8 +9 +10; 5+6+7 +8 +9 +10; 6+7 +8 +9 +10; 7 +8 +9 +10; 8 +9 +10; 9 +10 10];
Please note that this is a sample vector; I have a vector of 10000 X1 of random numbers and I want to do the same thing.
Is there any efficient code for that?
Maybe using movesum? I have tried but couldn't
I use MatlabR2020a
Best
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 28일
No, movesum is not going to help for that. movesum() deals with fixed length windows.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 28일
fliplr( cumsum( fliplr(a) ) )

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by