How to remove data noise through averaging adjacent elements in a data set.

I am trying to remove noise from my data that includes outliers which are skewing the final result. I'm wondering how I can average two adjacent elements sequentially for a whole data set in order to incorporate outliers more effectively and generate a more streamlined data set. For example, [a b c d e f g ...] it would look like (a+b)/2 and (c+d)/2 and (e+f)/2 ....and so on. I figured I should use a for loop but unsure what that would look like.

Answers (1)

x = 1:10
x = 1×10
1 2 3 4 5 6 7 8 9 10
One way:
xm = movmean(x,2)
xm = 1×10
1.0000 1.5000 2.5000 3.5000 4.5000 5.5000 6.5000 7.5000 8.5000 9.5000
xm = xm(2:2:end)
xm = 1×5
1.5000 3.5000 5.5000 7.5000 9.5000
Another way:
xm = mean(reshape(x,2,[]),1)
xm = 1×5
1.5000 3.5000 5.5000 7.5000 9.5000

2 Comments

You're welcome! Any questions, let me know. Otherwise, please "Accept This Answer". Thanks!

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 17 Nov 2022

Commented:

on 23 Nov 2022

Community Treasure Hunt

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

Start Hunting!