Remove specific outliers from double

6 Ansichten (letzte 30 Tage)
Konstantin Koerber
Konstantin Koerber am 16 Aug. 2023
Bearbeitet: Dyuman Joshi am 16 Aug. 2023
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 Kommentare
Konstantin Koerber
Konstantin Koerber am 16 Aug. 2023
Hey, thank you for your answer. I tried array2table but it didn't work. Since I want to keep the data in double array anyways, I'd prefer a different solution to only remove the outliers in the columns I want to. Any ideas?
Dyuman Joshi
Dyuman Joshi am 16 Aug. 2023
Bearbeitet: Dyuman Joshi am 16 Aug. 2023
"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)
144 2 3 141 13 131 130 16 25 119 -200 28 108 38 39 -300 96 50 51 93 61 83 82 64 73 71 70 76 60 86 87 57 48 98 99 45 109 35 34 112 121 23 22 124 12 134 135 9
%3rd column
isoutlier(A(:,3),"percentiles",[5 95])'
ans = 1×12 logical array
0 0 1 0 0 0 0 0 0 0 0 1
%4th column
isoutlier(A(:,4),"percentiles",[5 95])'
ans = 1×12 logical array
1 0 0 1 0 0 0 0 0 0 0 0
What should be the final output here?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 16 Aug. 2023
Use normal indexing to replace the outliers in certain columns using filloutliers.
A = magic(5);
A(3, :) = A(3, :) + 100 % Create outliers
A = 5×5
17 24 1 8 15 23 5 7 14 16 104 106 113 120 122 10 12 19 21 3 11 18 25 2 9
A(:, [2 4]) = filloutliers(A(:, [2 4]), NaN)
A = 5×5
17 24 1 8 15 23 5 7 14 16 104 NaN 113 NaN 122 10 12 19 21 3 11 18 25 2 9
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]))
Unable to perform assignment because the size of the left side is 5-by-2 and the size of the right side is 4-by-2.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by