How to identify outliers and remove?

10 vues (au cours des 30 derniers jours)
pink flower
pink flower le 14 Déc 2020
Hello!
I have a .txt file with a lot of data and I need to identify and remove outliers. I already tried the command
rmoutliers
but it returns:
Undefined function or variable 'rmoutliers'.
Does anyone have any solution that can help me? I use MATLAB R2017a.
  1 commentaire
Rik
Rik le 14 Déc 2020
You will have to use a different function: that one was introduced in R2018b.
Have you tried Google? I alread see two links to file exchange submission in the sidebar (one and two). Have you looked at anything on the FEX and what functions those submissions use?

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 14 Déc 2020
pink, you can try it yourself with movmedian(), introduced in R2016a. Try this demo I made especially for you.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
fprintf('Beginning to run %s.m ...\n', mfilename);
% Create sample noisy data.
x = linspace(0, 4*pi, 1000);
y = sin(x) + 0.1 * rand(1, length(x));
% Get 20 random indexes where we can add noise.
noiseIndexes = sort(randperm(length(x), 20));
y(noiseIndexes) = y(noiseIndexes) + 0.75 + rand(1, length(noiseIndexes));
subplot(3, 1, 1);
plot(x, y, 'b-');
grid on;
title('Original Signal', 'FontSize', fontSize);
% Smooth the signal with a median filter.
ySmooth = movmedian(y, 9);
% Get the median absolute deviation everywhere.
madValues = abs(y - ySmooth);
subplot(3, 1, 2);
plot(x, madValues, 'b-');
grid on;
title('MAD Signal', 'FontSize', fontSize);
% Find the bad indexes where MAD > 3
outlierIndexes = madValues > 0.3; % You can adjust this.
hold on;
plot(x(outlierIndexes), madValues(outlierIndexes), 'ro', 'LineWidth', 2);
grid on;
% Repair the signal by replacing the outlier locations
% with the smoothed signal at those locations.
y(outlierIndexes) = ySmooth(outlierIndexes);
subplot(3, 1, 3);
plot(x, y, 'b-');
grid on;
title('Repaired Signal', 'FontSize', fontSize);
If that doesn't work, then attach your signal with the paper clip icon.

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by