0

To remove data above 1.2 and below -1.2.

I use the following function:

threshold = [-1.2, 1.2];
y = rmoutliers(y,'percentiles',threshold);

But error occurred:

Error using isoutlier>parseinput (line 236) 'Percentiles' value must be a sorted 2-element numeric vector with entries between 0 and 100.

Any other functions which can be used to solve the problem?

Cyan
  • 82
  • 9

2 Answers2

1

Removing them is straight forward. Assuming you need to remove the points from both the x and y axis data then,

idx_to_remove = ((y<-1.2)|(y>1.2));
x(idx_to_remove) = [];
y(idx_to_remove) = [];

But do you need to remove them or saturate them to the appropriate limit instead? For saturation x wouldn't change, but you'd do the following to y,

y(y < -1.2) = -1.2;
y(y > 1.2) = 1.2;
Phil Goddard
  • 10,571
  • 1
  • 16
  • 28
1

If you want to leave the x axis variable unchanged (i.e. the number of elements should stay the same), it would be a good idea to convert the outliers to NaN.

y( abs(y)>1.2 ) = NaN;

If you want to remove the elements, you can use [] instead of NaN.

y( abs(y)>1.2 ) = [];

This condition abs(y)>1.2 tests for an absolute (positive) value greater than 1.2, if your thresholds were different then you could test them separately

y( y > 1.2 | y < -1.2 ) = NaN;
Wolfie
  • 27,562
  • 7
  • 28
  • 55