How to identify outliers and remove?

조회 수: 5 (최근 30일)
pink flower
pink flower 2020년 12월 14일
답변: Image Analyst 2020년 12월 14일
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
Rik
Rik 2020년 12월 14일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 12월 14일
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.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by