How to add every other number in a row?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am quite new to matlab. I've been trying to add every other number in a 1x53. For example, it gives say 1 2 3 4..., how do I make it into 1 2+1 3+2+1 4+2+3+1 which would give 1 3 5 10?
this is my data
t = [21.3222640867819 17.3750802156164 14.5582686903576 12.6001062285850 11.8611536681443 11.5892376766466 11.4590658136099 11.4561559814220 11.8273436783477 12.2346997542733 12.6663456083089 13.1248884765231 13.6133343555447 14.1560488223624 14.7390294714380 15.3675434711385 16.0478264373233 16.8166063298431 17.6586366542217 18.5859382681035 19.6133059849360 20.8048315931557 22.1489156164215 23.6786431312492 25.4373517749143 27.5646079504175 30.0867647466357 33.1284333916116 36.8725732613024 41.7926940720638 48.2689652602893 57.1866880790909 70.2579667937006 73.5212188601740 77.1993926487091 81.3811191237218 86.1760561669322 116.245636739297 179.602580001465 399.168759934324]
Thank you!
0 commentaires
Réponse acceptée
Image Analyst
le 18 Nov 2022
Modifié(e) : Image Analyst
le 18 Nov 2022
Explain again how you want 5. Because 3 + 2 + 1 = 6, not 5.
And how is 4+3+2+1 adding only every other element? It looks like it's adding every single element to me? Did you really think this question through?
v = 1:4
c = cumsum(v)
t = [21.3222640867819 17.3750802156164 14.5582686903576 12.6001062285850 11.8611536681443 11.5892376766466 11.4590658136099 11.4561559814220 11.8273436783477 12.2346997542733 12.6663456083089 13.1248884765231 13.6133343555447 14.1560488223624 14.7390294714380 15.3675434711385 16.0478264373233 16.8166063298431 17.6586366542217 18.5859382681035 19.6133059849360 20.8048315931557 22.1489156164215 23.6786431312492 25.4373517749143 27.5646079504175 30.0867647466357 33.1284333916116 36.8725732613024 41.7926940720638 48.2689652602893 57.1866880790909 70.2579667937006 73.5212188601740 77.1993926487091 81.3811191237218 86.1760561669322 116.245636739297 179.602580001465 399.168759934324]
c = cumsum(t, 2)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!