Removing Outbound (out of range) data from an array

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,

 채택된 답변

Fabio Freschi
Fabio Freschi 2019년 11월 7일
% 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);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by