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)
Show older comments
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
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);
8 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!