how to calculate the average (for each three values of y)
y=[2 3 5 3 4 2 3 4 5 3 2 7 8 6 5 5 4 3 3 3 2 ]
you should take each three values and find the average for them
x(1 to 3)= (y(1)+y(2)+y(3))/3 =(2+3+5)/3 =10/3 = 3.33333
x(4 to 6)= (y(4)+y(5)+y(6))/3 =(3+4+2)/3 =9/3 =3
x(7 to 9)= (y(7)+y(8)+y(9))/3 =(3+4+5)/3 =12/3 =4
.
.
.
x(19 to 21)= (y(19)+y(20)+y(21))/3 =(3+3+2)/3 =8/3 =2.66so your answer will be
x= [ 3.3333 3.3333 3.3333 3.0000 3.0000 3.0000 4.0000 4.0000 4.0000 4.0000 4.0000 4.0000 6.3333 6.3333 6.3333 4.0000 4.0000 4.0000 2.6667 2.6667 2.6667 ]
note: you need to transpose x as final answer
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers81
Suggested Problems
-
Find the sum of all the numbers of the input vector
55982 Solvers
-
The Hitchhiker's Guide to MATLAB
3431 Solvers
-
Project Euler: Problem 6, Natural numbers, squares and sums.
2595 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
406 Solvers
-
Matlab Basics II - Count rows in a matrix
412 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
this is not really a moving average.
This is not really moving average as it was said by Marcel. The moving average moves forward 1 space at a time. However, it is possible to use the moving average for finding the solution.