calculating the mean of specific array using previous & next array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sehoon Chang
am 6 Apr. 2020
Beantwortet: the cyclist
am 6 Apr. 2020
Dear all,
I am trying to find a way to calculate the mean of specific array in a vector.
Within the vector "W", there are "outliers".
In order to adjust the values of the outliers, i wish to calculate the mean at the position of the outlier using previous (outlier-1) and next (outlier+1) value of outlier.
And once done, the calculate mean values should replace the value of outliers.
assumed values as an example;
W = randi([0 50], 1, 18000)
outliers = [1224 1370 1485 3001 ........ ]
Thanks all
1 Kommentar
Akzeptierte Antwort
the cyclist
am 6 Apr. 2020
The variable outliers contains the indices to the outlier locations, right? Then
W(outliers) = (W(outliers-1) + W(outliers+1))/2;
will replace those locations with the mean of that locations nearest neighbors.
There are two scenarios where this simple formula will not work:
- One could have outliers at two consecutive indices
- The outlier could be at the first or last element of your array.
You'll need to provide more info on how you want to handle those special cases.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!