How to remove outliers in a 3D surface

42 次查看(过去 30 天)
HAMID
HAMID 2021-11-6
评论: Chris 2021-11-7
I have a 3D surface (see below) construced using surf command based on excel data:
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/791474/excel-surface.xlsx')
x = T.(1) ;
y = T.(2) ;
z = T.(3) ;
xi = linspace(min(x),max(x));
yi = linspace(min(y),max(y)) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
surf(X,Y,Z)
shading interp
colorbar
The resulting surface is as follows:
However, I know that the surface should be smooth without these "peaks" that appear randomly from above or below.
Is there a way to remove these outliers and interpolate to construct a smooth surface? (NOTE, I AM NEW TO MATLAB).

回答(2 个)

Matt J
Matt J 2021-11-6
You could try rmoutliers().
  5 个评论
Matt J
Matt J 2021-11-6
I would have to see what you tried in order to be able to guess what's not working.

请先登录,再进行评论。


Chris
Chris 2021-11-6
编辑:Chris 2021-11-6
I would recommend trying the "clean outlier data" task in the live editor, after sorting the data:
T = sortrows(T,1); % Sort by the first column ('x')
Open a New Live Script, and select the task.
Select the table and input variable z.
I can get decent results with spline interpolation, a centered moving median, and a low threshold. But I'm not sure how, computationally, you would create a perfectly smooth surface that retains the contours you would want to see, as there are quite a few clumped outliers.
Perhaps repeated sorting by x and y, with outlier cleaning in between, could work.
  2 个评论
HAMID
HAMID 2021-11-7
clear; clc;
% Read table:
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/791474/excel-surface.xlsx')
% Fill outliers:
T = sortrows(T,1);
T.Z = filloutliers(T.Z, "spline", "movmedian", 4);
T = sortrows(T,2);
T.Z = filloutliers(T.Z, "spline", "movmedian", 4);
% Plot surface:
x = T.(1) ;
y = T.(2) ;
z = T.(3) ;
xi = linspace(min(x),max(x));
yi = linspace(min(y),max(y)) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
surf(X,Y,Z)
shading interp
colorbar
I tried sorting multiple times but it is not working. I now have a new weird outlier.
Before:
After:
Chris
Chris 2021-11-7
clear; clc;
% Read table:
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/791474/excel-surface.xlsx');
% Fill outliers:
for idx = 1:2
for jdx = 8:-2:2
T = sortrows(T,1);
T.Z = filloutliers(T.Z, "spline", "movmedian", jdx);
T = sortrows(T,2);
T.Z = filloutliers(T.Z, "spline", "movmedian", jdx);
end
end
% Plot surface:
x = T.(1) ;
y = T.(2) ;
z = T.(3) ;
xi = linspace(min(x),max(x));
yi = linspace(min(y),max(y)) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
surf(X,Y,Z)
% shading interp
colorbar
Getting pretty close.
With default shading, you'll see there are still a few bumps. But you can also see interesting features. Repeating the process, and changing the window size, continues to smooth the surface.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Smoothing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by