For Loop that loops n times for moving average

7 Ansichten (letzte 30 Tage)
Amanda
Amanda am 7 Feb. 2021
Beantwortet: the cyclist am 7 Feb. 2021
Hello,
How can I write a for loop that loops 4 times and is a moving average where it creates a new variable called MovingMean5 where the 1st element is the average of the elements 1 to 5 from the dataname variable. Then the 2nd element of MovingMean5 is the mean of the dataname variable from elements 2 to 6. Then the 3rd element of MovingMean5 is the mean of the dataname variable from elements 3 to 7. Then the 3rd element of MovingMean5 is the mean of the dataname variable from elements 4 to 8.
I have no idea what to write for the script. This is what I have so far, but it isn't working:
for i = 1:5
MovingMean5(i) = mean(dataname(1:i+5));
end
please help

Antworten (1)

the cyclist
the cyclist am 7 Feb. 2021
Perhaps just use the movmean command instead?

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by