Borrar filtros
Borrar filtros

Methods for smoothing contour lines

7 visualizaciones (últimos 30 días)
Andrew Sol
Andrew Sol el 20 de Oct. de 2022
Comentada: Star Strider el 21 de Oct. de 2022
I have a database P with columns X, Y and Z (file above):
N = 150; % Number Of Points Desired
xv = linspace(min(P(:,1)), max(P(:,1)), N);
yv = linspace(min(P(:,2)), max(P(:,2)), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(P(:,1), P(:,2), P(:,3), X, Y);
contourf(X, Y, Z, 35)
Zi = interp2(P(:,1), P(:,2), P(:,3), X, Y) ;
With the code above, I get the following plot:
How to make contour lines neater and smoother?

Respuesta aceptada

Star Strider
Star Strider el 20 de Oct. de 2022
Editada: Star Strider el 20 de Oct. de 2022
I dislike going to external sites.
Increasing ‘N’ would be the option I would use, initially experimenting with 250 and perhaps 500 or greater, depending on the available memory and the result provided. That should increase the resolution of the vectors, and therefore the resolution of the matrices derived from them.
EDIT — (20 Oct 2022 at 15:45)
Using the supplied data —
LD = load(websave('P','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1163343/P.mat'));
P = LD.P;
N = 500; % Number Of Points Desired
xv = linspace(min(P(:,1)), max(P(:,1)), N);
yv = linspace(min(P(:,2)), max(P(:,2)), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(P(:,1), P(:,2), P(:,3), X, Y);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
figure
contourf(X, Y, Z, 35)
I looked at the first column of ‘P’ to see if reshaping would work. It will not, because the first indices of the different unique values of ‘P(:,1)’ do not have constant distances between them.
The data simply do not appear to be smooth (i.e. may have limited precision), and that is reflected in the contours even with a relatively high precision in the interpolating matrices.
This is likely as good as it gets.
.
  18 comentarios
Andrew Sol
Andrew Sol el 21 de Oct. de 2022
And thank you for not passing by!
Star Strider
Star Strider el 21 de Oct. de 2022
As always, my pleasure!
This was an interesting problem!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by