Remove certain rows from cell array that deviates by more than 10 mean absolute deviations from a rolling centered median (excluding the observation under consideration) of 50 observations (25 observations before and 25 after).

1 view (last 30 days)
I have a cellarray A which has 10 columns of which i need to apply this condition - "deviated by more than 10 mean absolute deviations from a rolling centered median (excluding the observation under consideration) of 50 observations (25 observations before and 25 after)" on column 7 of each cell and then remove those rows from cells. And i need to put another condition on column 6 of each cell that - if it is more than 50 times the median value, then i need to remove those rows too.
Suugest a faster way to put both these conditions on each cell and subsequently remove those rows from each cell.Using R2016a

Answers (1)

Image Analyst
Image Analyst on 7 Jan 2019
Try this. Replace my col7 with the data from your column 7. It extracts only the good data from col7. Bad data are identified by magenta asterisks. Requires the Signal Processing toolbox to get the moving median filter, medfilt1().
% Create sample data
col7 = randn(1, 1000) + 1;
% Make outliers
col7(50:100:end) = 30;
medianFilteredSignal = medfilt1(col7, 51);
x = 1 : length(col7);
plot(x, col7, 'b-');
grid on;
ylim([-1, 31]);
hold on;
plot(x, medianFilteredSignal, 'r-');
% Identify good signals where the difference between the
% mean signal and median filtered signal is less than 10 times the
% median filtered value.
goodIndexes = abs(col7 - medianFilteredSignal) < 10 * medianFilteredSignal;
badIndexes = ~goodIndexes;
% Plot a star over the bad points.
plot(x(badIndexes), col7(badIndexes), 'm*', 'MarkerSize', 15, 'LineWidth', 2);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Extract only the good points:
col7Good = col7(goodIndexes);
0000 Screenshot.png
  8 Comments
NS
NS on 8 Jan 2019
Edited: NS on 8 Jan 2019
Sir basically i want to replicate this R package code rmOutliers (Page 60) and rmLargeSpread(Page 59) in highfreuency package - https://cran.r-project.org/web/packages/highfrequency/highfrequency.pdf in MATLAB.
Kindly see these two codes for any other clarity.
NS
NS on 8 Jan 2019
Dear Sir
Any help on this ? Its basically how you clean a quote data in finance using these two conditions on each day.

Sign in to comment.

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!