How to remove outliers in a 3D surface

24 ビュー (過去 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 Center および File ExchangeSmoothing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by