本文介绍了如何消除Matlab中向量的突然变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的向量如下图所示.根据常识,我们可以看到有两个突然偏离向量趋势的值.

Assume that I have vector shown in the figure below. By common sense, we can see that there are 2 values which suddenly depart from the trend of the vector.

如何消除这些突然的变化.我的意思是我该如何自动检测这些噪声值并将其替换为邻居的平均值.

How do I eliminate these sudden changes. I mean how do I automatically detect and replace these noise values by the average value of their neighbors.

推荐答案

定义一个阈值,计算平均值,然后比较这些值与其邻居的平均值之间的相对误差:

Define a threshold, compute the average values, then compare the relative error between the values and the averages of their neighbors:

threshold  = 5e-2;
averages   = [v(1); (v(3:end) + v(1:end-2)) / 2; v(end)];
is_outlier = (v.^2 - averages.^2) > threshold^2 * averages.^2;

然后替换异常值:

v(is_outlier) = averages(is_outlier);

这篇关于如何消除Matlab中向量的突然变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:27