Effacer les filtres
Effacer les filtres

Summing elements of a vector sequentially?

4 vues (au cours des 30 derniers jours)
James
James le 31 Mai 2015
Commenté : James le 31 Mai 2015
Is there a function that will sum a vector in the following way?
Let x be a 1 x N vector. The ith element of the output vector should be sum(x(1:i)), where i ranges from 1 to N.
I will use a for loop, if I must...
x = 1:100;
output = zeros(1,length(x))
for i = 1:length(x), output(i) = sum(x(1:i)); end
Thanks!

Réponse acceptée

per isakson
per isakson le 31 Mai 2015
See cumsum
  1 commentaire
James
James le 31 Mai 2015
I had a feeling there would be a function dedicated to this. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by