Adding elements of a vector in matlab

4 vues (au cours des 30 derniers jours)
ektor
ektor le 28 Mai 2020
Commenté : Walter Roberson le 28 Mai 2020
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 commentaire
Walter Roberson
Walter Roberson le 28 Mai 2020
No, movesum is not going to help for that. movesum() deals with fixed length windows.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 28 Mai 2020
fliplr( cumsum( fliplr(a) ) )

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays 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