Effacer les filtres
Effacer les filtres

How do I return The Average of particular row incriment in a vector?

2 vues (au cours des 30 derniers jours)
Arief Yoga Randytama
Arief Yoga Randytama le 22 Avr 2021
Commenté : Jonas le 22 Avr 2021
Hi, suppose i want to return vector B which is the average of the first n column of a vector A and the next n and so on. What should the algorithm be? For example here i take n=3, The vector A is the input, and B is the desired result. Thanks!
A = [1 1 1 2 2 2 5 5 8]
B = [1 2 6]
  1 commentaire
Jonas
Jonas le 22 Avr 2021
you could reshape you vector to a matrix using reshape, then calculate the mean along the dimension in which reshape puts the elements (dont know at the moment of reshape fills row by row or column by column)

Connectez-vous pour commenter.

Réponses (1)

the cyclist
the cyclist le 22 Avr 2021
A = [1 1 1 2 2 2 5 5 8];
n = 3;
B = mean(reshape(A,n,[]))
B = 1×3
1 2 6

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by