apparently the command rmoutliers does not do the job correctly
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammad Shojaei Arani
le 14 Nov 2022
Commenté : Mohammad Shojaei Arani
le 14 Nov 2022
Hello,
It seems to me that the command "rmoutliers" has some problems. To make things clear I explain using an example as bellow:
>> a=[1 2 3 4 1000 6;2 5000 3 4 0 1];a
[b1,idx1] = rmoutliers(a(1,:));[b2,idx2] = rmoutliers(a(2,:));[b,idx] = rmoutliers(a,2);
idx1
idx2
idx
a =
1 2 3 4 1000 6
2 5000 3 4 0 1
idx1 =
0 0 0 0 1 0
idx2 =
0 1 0 0 0 0
idx =
0 0 0 0 0 0
This does not make sense to me. so, if I am right then this command needs to be corrected. The second problem with this command is that it apparently can no longer have 3 outputs (unlike what is written in the corresponding matlab page). So, if you try the following then you get error message:
[b,idx,u] = rmoutliers(a,2);
Any comment?
thsnks in advance!
Babak
3 commentaires
Stephen23
le 14 Nov 2022
Modifié(e) : Stephen23
le 14 Nov 2022
"So, if I understood correctly the command [b,idx] = rmoutliers(a,2); should find outliers in each row..."
No. Nowhere in the RMOUTLIERS documentation is it stated that RMOUTLIERS checks anything other than columns: the documentation states for a matrix "...then rmoutliers detects outliers in each column of A separately..."
"...and then remove the corresponding columns?"
Yes. The DIM argument is specifically described as "specifies the dimension of A for which to remove entries when an outlier is detected using any of the previous syntaxes. For example, rmoutliers(A,2) removes columns instead of rows for a matrix A" (bold emphasis added). Note that the DIM description does not state that it changes which dimension the MEDIAN is calculated over, all this option changes is whether rows/columns are removed.
Simple solution: transpose the input matrix.
Réponse acceptée
Steven Lord
le 14 Nov 2022
Rather than going directly to rmoutliers I recommend using isoutlier to detect the outliers then process the resulting logical array.
a=[1 2 3 4 1000 6;2 5000 3 4 0 1];
[b1,idx1] = rmoutliers(a(1,:));
[b2,idx2] = rmoutliers(a(2,:));
bRow = isoutlier(a, 2)
columnsWithOutliers = any(bRow, 1)
originalData = a % Make a copy so you can compare the original and processed data
a(:, columnsWithOutliers) = []
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!