apparently the command rmoutliers does not do the job correctly
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mohammad Shojaei Arani
il 14 Nov 2022
Commentato: Mohammad Shojaei Arani
il 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 Commenti
Stephen23
il 14 Nov 2022
Modificato: Stephen23
il 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.
Risposta accettata
Steven Lord
il 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) = []
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!