Remove specific outliers from double
11 次查看(过去 30 天)
显示 更早的评论
I want to remove outliers from a double using the rmoutliers function, combied with "datavariables" to select the columns from which the outliers should be removed. See the code below.
mData3=rmoutliers(mData3,'percentiles',[5 95],'DataVariables',[3 4]);
The addition of the "datavariables" argument messes with the function and leads to no output. It seems that it only works with a table datatype, however I am unable to convert the double to a table. (I also need the data to be in the double-form)
Is there another solution?
Kind regards
3 个评论
Dyuman Joshi
2023-8-16
编辑:Dyuman Joshi
2023-8-16
"I tried array2table but it didn't work."
Can you attach your code and data?
Suppose your data is this -
A = magic(12);
A = A(:,1:4);
A(3,3) = -200;
A(4,4) = -300;
disp(A)
%3rd column
isoutlier(A(:,3),"percentiles",[5 95])'
%4th column
isoutlier(A(:,4),"percentiles",[5 95])'
What should be the final output here?
回答(1 个)
Steven Lord
2023-8-16
Use normal indexing to replace the outliers in certain columns using filloutliers.
A = magic(5);
A(3, :) = A(3, :) + 100 % Create outliers
A(:, [2 4]) = filloutliers(A(:, [2 4]), NaN)
Note that you can't remove outliers in this scenario, as that would lead to a matrix with different length columns and that is not allowed in MATLAB numeric arrays.
A(:, [1 5]) = rmoutliers(A(:, [1 5]))
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!