MATLAB: Modify the given vector x=[1.1 1.4 1.9 2.1 1.3 1.7 1.8 5 1.5] by elimination of values that differ by more than the standard deviation from the mean value of the given sequence.

modify the given vector

Could you please provide me some solution for this question? Possibly using loops. Mean =2.0 ; Stdev = 1.2;

Best Answer

Feeling loopy tonight, but not that loopy!
Try this, avoiding the loopys:
x=[1.1 1.4 1.9 2.1 1.3 1.7 1.8 5 1.5];
x_mean = mean(x);
x_stdv = std(x);
limits = [-x_stdv x_stdv]+x_mean;
x_dev = (x<=limits(1)) | (x>=limits(2)) % Logical Vector wheren ‘1’ (True) Meets The Criteria And ‘0’ (False) Fails To Meet It
_dev =
1×9 logical array
0 0 0 0 0 0 0 1 0