如何在 MATLAB 中有效找到相关性并丢弃 3-sigma 范围之外的点?

发布于 2024-08-11 05:50:02 字数 582 浏览 4 评论 0原文

我有一个数据文件 m.txt ,看起来像这样(有更多点):

286.842995
3.444398
3.707202
338.227797
3.597597
283.740414
3.514729
3.512116
3.744235
3.365461
3.384880

一些值(如 338.227797)是 与我通常期望的值(较小的数字)非常不同。

  • 所以,我想 我将删除位于 3-sigma 范围之外的所有点。我怎样才能在 MATLAB 中做到这一点?

  • 此外,更大的问题是该文件有一个与之关联的单独文件 t.txt,该文件存储这些数字对应的时间值。因此,我还必须从 t.txt 文件中删除相应的时间值。

我仍在学习 MATLAB,并且我知道有一些好的方法可以做到这一点(比存储从 m.txt 中删除的元素的索引,然后从 中删除这些元素更好) t.txt 文件)

I have a data file m.txt that looks something like this (with a lot more points):

286.842995
3.444398
3.707202
338.227797
3.597597
283.740414
3.514729
3.512116
3.744235
3.365461
3.384880

Some of the values (like 338.227797) are very different from the values I generally expect (smaller numbers).

  • So, I am thinking that
    I will remove all the points that lie outside the 3-sigma range. How can I do that in MATLAB?

  • Also, the bigger problem is that this file has a separate file t.txt associated with it which stores the corresponding time values for these numbers. So, I'll have to remove the corresponding time values from the t.txt file also.

I am still learning MATLAB, and I know there would be some good way of doing this (better than storing indices of the elements that were removed from m.txt and then removing those elements from the t.txt file)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ら栖息 2024-08-18 05:50:02

@Amro 很接近,但 FIND 是不必要的(查找逻辑下标),并且您需要包含真正的 +/-3 sigma 范围的平均值。我会选择以下内容:

%# load files 
m = load('m.txt'); 
t = load('t.txt'); 

%# find values within range
z = 3;
meanM = mean(m);
sigmaM = std(m);
I = abs(m - meanM) <= z * sigmaM;

%# keep values within range
m = m(I);
t = t(I); 

@Amro is close, but the FIND is unnecessary (look up logical subscripting) and you need to include the mean for a true +/-3 sigma range. I would go with the following:

%# load files 
m = load('m.txt'); 
t = load('t.txt'); 

%# find values within range
z = 3;
meanM = mean(m);
sigmaM = std(m);
I = abs(m - meanM) <= z * sigmaM;

%# keep values within range
m = m(I);
t = t(I); 
七月上 2024-08-18 05:50:02
%# load files
m = load('m.txt');
t = load('t.txt');

%# find outliers indices
z = 3;
idx = find( abs(m-mean(m)) > z*std(m) );

%# remove them from both data and time values
m(idx) = [];
t(idx) = [];
%# load files
m = load('m.txt');
t = load('t.txt');

%# find outliers indices
z = 3;
idx = find( abs(m-mean(m)) > z*std(m) );

%# remove them from both data and time values
m(idx) = [];
t(idx) = [];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文