How do I remove outliers from a matrix?
Afficher commentaires plus anciens
I want to remove outliers from a 3000x3 matrix where each of the 3 columns has a different type of data. I want to remove observations that are different from the mean/median by 3 standard deviations in each column. However, if there is an outlier at (400,1), for example, then I want (400,2) and (400,3) to also be removed regardless of whether they are outliers or not- i.e. if there is an outlier detected then the entire ROW is removed.
Any ideas on how to make a simple script to do this ?
Thanks
Réponses (2)
Thorsten
le 3 Août 2016
idx = bsxfun(@gt, R, mean(R) + std(R)) | bsxfun(@lt, R, mean(R) - std(R));
idx = any(idx, 2);
R(idx, :) = [];
KSSV
le 3 Août 2016
If you know the row index you can remove the complete row using data(idx,:) = [] ;
Eg:
data = rand(10,3) ;
idx = find(data(:,1)>0.5) ; % from first column get values greater then 0.5
data(idx,:) = [] ; % removes the rows idx from data
Catégories
En savoir plus sur Hypothesis Tests dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!