adding vector entry after each element
Afficher commentaires plus anciens
This is a very basic question but how would I add the elements of a vector like so...:
x = [1,2,3,4,5,6];
ans = 3 6 10 15 21
Réponse acceptée
Plus de réponses (1)
Sean de Wolski
le 15 Août 2012
And just for fun:
filter(x(2:end),1,ones(1,numel(x)-1))+x(1)
1 commentaire
While we're on the topic of ridiculously inefficient alternatives to CUMSUM, ;-)
sum(triu(toeplitz(x(2:end))))+x(1)
Catégories
En savoir plus sur Interpolation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!