Filter data directly in scatter graph
Show older comments
I am new to MATLAB, I want to filter some data on the image I send attached, I tried to use smooth funciton but I think it only works with plot and I want to be able to use it with the scatter function. I know I can erase this dots manually with the brush/select data directly in the graph, the thing is I have tens of this graphs. I want to be able to filter them in the graph not in the workspace. Is it even possible to do this? thanks.
4 Comments
Adam Danz
on 13 Nov 2018
Your image doesn't appear.
Adam Danz
on 13 Nov 2018
Looks like the question was edited but the image still doesn't appear. I wonder if you're experiencing a glitch in the updated format of the website.
Sebastian Guzman
on 13 Nov 2018
There's lots of approaches to this problem.
1) Smoothing. Smoothing will definitely clean up the data but you'll have a bump around x=~900 where those cluster of data points are and you'll lose some of the features of the data like the sudden steps around x=~2800 and x=~3500.
2) Fitting. If you know what the shape of the line "should" be, you can fit the data to a function. In that case you'll end up with a very smooth line but you'll lose all of the variation.
3) Removing outliers. Matlab has several algorithms for detecting outliers in your data. You could detect the outliers and then remove them. That will preserve the main features of your data. For example, if you're using matlab 2017a or later, see
doc isoutlier()
.
Depending on your approach, there's lots of functions, tools, etc that matlab offers. But first you should decide on an approach which depends on how the data will be used, interpreted, etc.
Answers (1)
Let (x,y) be your data.
stdDev = std(y) ; % Compute standard deviation
meanValue = mean(y) ; % Compute mean
zFactor = 1.5; % or whatever you want.
% indices where outliers are present
idx = abs(y-meanValue) > (zFactor * stdDev);
% remove outliers
x(idx) = [] ;
y(idx) = [] ;
plot(x,y,'.')
1 Comment
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!