Borrar filtros
Borrar filtros

How to remove outliers in a 3D surface

42 visualizaciones (últimos 30 días)
HAMID
HAMID el 6 de Nov. de 2021
Comentada: Chris el 7 de Nov. de 2021
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).

Respuestas (2)

Matt J
Matt J el 6 de Nov. de 2021
You could try rmoutliers().
  5 comentarios
Matt J
Matt J el 6 de Nov. de 2021
I would have to see what you tried in order to be able to guess what's not working.
HAMID
HAMID el 7 de Nov. de 2021

Iniciar sesión para comentar.


Chris
Chris el 6 de Nov. de 2021
Editada: Chris el 6 de Nov. de 2021
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 comentarios
HAMID
HAMID el 7 de Nov. de 2021
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 el 7 de Nov. de 2021
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Smoothing en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by