MATLAB excluding data beyond 1 standard deviation

I'm inexperienced with MATLAB, so sorry for the beginners question:

I have a large vector (905350 elements) storing a whole bunch of data in it. I have standard deviation and mean, and now I want to cut out all data points that are above / below one standard deviation from the mean. I just have no idea. From what I'm going to, do I need to do a double loop?

It looks like: mean-std <data I want <mean + std

+3
source share
4 answers

If the data is in variable A , while the average value is stored in meanA and the standard deviation stored in stdA , then the following will extract the necessary data, while preserving the original order of the data values:

 B = A((A > meanA-stdA) & (A < meanA+stdA)); 

Here are some useful documentation links that relate to the concepts used above: logical operators , matrix indexing .

+5
source

You can simply use Element-wise boolean AND :

 m = mean(A); sd = std(A); B = A( A>m-sd & A<m+sd ); 

Furthermore, knowing that: |x|<c iff -c<x<c , you can combine both in one:

 B = A( abs(Am)<sd ); 
+6
source

Take A as the initial vector, and B as the final:

 B = sort(A) B = B(find(B > mean-std,1,'first'):find(B < mean+std,1,'last')) 
0
source
 y = x(x > mean-std); y = y(y < mean+std); 

must work. See FIND for more details. The FIND command is used implicitly in the code above.

0
source

Source: https://habr.com/ru/post/1304629/


All Articles