How to remove outliers in a 3D surface

조회 수: 28 (최근 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.
HAMID
HAMID 2021년 11월 7일

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


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