使用VBAfunction清洁和平滑Excel图表

我需要平滑和清理一个ping数据图表(截图上的橙色),以提高阅读体验。 – 清洗:以当地平均值取代1平时的时间,但不是很多时间超顺滑 – 平滑:用当地平均值代替小振荡值,而是保存突变的date时间

平/带宽

我写这个VBA代码(Excel函数平滑),把它放在你的工作簿的一个新的VBA模块中,并在你的数据系列上使用它:

在这里输入图像说明

Public Function Smoothing(ByVal Values As range) ' il faudrait plutot chercher les valeurs aberante et les retirer AverageAvec = Application.Average(Values) EcartTypeAvec = Application.StDevP(Values) EcartTypeRef = EcartTypeAvec Smoothing = AverageAvec For Each cell In Values AverageSans = Application.Average(SetDifference(Values, cell)) EcartTypeSans = Application.StDevP(SetDifference(Values, cell)) If EcartTypeSans < EcartTypeRef Then EcartTypeRef = EcartTypeSans If EcartTypeAvec > EcartTypeRef * 1.3 Then Smoothing = AverageSans End If End If Next End Function Function SetDifference(ByVal Rng1 As range, ByVal Rng2 As range) As range On Error Resume Next If Intersect(Rng1, Rng2) Is Nothing Then 'if there is no common area then we will set both areas as result Set SetDifference = Union(Rng1, Rng2) 'alternatively 'set SetDifference = Nothing Exit Function End If On Error GoTo 0 Dim aCell As range For Each aCell In Rng1 Dim Result As range If Application.Intersect(aCell, Rng2) Is Nothing Then If Result Is Nothing Then Set Result = aCell Else Set Result = Union(Result, aCell) End If End If Next aCell Set SetDifference = Result End Function 

我的代码search对标准差有最大影响的值,排除它来计算新的本地平均值。

橙色是平滑的

对于3个单元格范围来说是一个很好的实现,但是对于更多的单元格范围(为了提高平滑效果)的WARNING ,如果很多值对标准偏差有重要影响,只有一个已经被删除!