Removing Outbound (out of range) data from an array

35 views (last 30 days)
I have an array which includes 3 million data points. The average of this array in equal to 10 but the variance is too much. However, I tried to use moving average to decreace the variance but I'm looking for a way to remove the out of range data from the array before taking moving average. For instance, in my array, most of the numbers of between 5 and 15 but also I have some numbers that are about 200000. How can I delete unwanted data points from my array?. Is there any function for that?. Basically, I know the logical range of the numbers in the array, and I just want the numbers in that range.
I appreciate your kind help in advance,

Accepted Answer

Fabio Freschi
Fabio Freschi on 7 Nov 2019
% dimension
N = 1000000;
% data in (0,1)
x = rand(N,1);
% threshold
xMin = 0.25;
xMax = 0.75;
% remove data out of the range
x(x < xMin |x > xMax) = [];
% or (this is faster for large datasets)
xKept = x(x < xMax);

More Answers (0)

Categories

Find more on Analysis, Benchmarking, and Verification in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by