Unable to get similar contour using the gridfit
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sanjeet
el 21 de Ag. de 2015
Respondida: John D'Errico
el 19 de Sept. de 2015
I am trying to plot countour filled for the data- i got a contour using the tri-contour- gives lines,
tri = delaunay(y1,z1); %A 2-D Delaunay triangulation ensures that the circumcircle associated with each triangle contains no other point in its interior
tricontour(tri,y1,z1,log10(mass2*1e6),contourlevel);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148324/image.png)
Since i need the colormap form plot: I used the gridfit to achieve that, but getting different plot nature
x_node= -50:01: 50;
y_node= -100:01: 0;
% % techniques to fit the function to the grid points
% % it reduces the data points to get you less levels
[zg,xg,yg] = gridfit(y1,z1,(log10(mass2*1e6)),x_node,y_node,'interp', 'nearest');
contourf(xg,yg,zg,50)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/148326/image.png)
0 comentarios
Respuesta aceptada
Kelly Kearney
el 24 de Ag. de 2015
Gridfit isn't really appropriate for extrapolation, and if you use it for that you often get surfaces that increase/decrease sharply outside of your data domain. That's what's happening here, since you apply the surface-fitting to a region much larger than that of your data. I'd trim off anything that extends beyond the convex hull of your input data prior to contouring. I'd also be careful using the 'nearest' option in gridfit; the documentation mentions that this will rarely be the best option.
x_node = linspace(min(y1), max(y1), 100);
y_node = linspace(min(z1), max(z1), 100);
[zg,xg,yg] = gridfit(y1,z1,(log10(mass2*1e6)),x_node,y_node);
k = convhull(x,y);
isin = inpolygon(xg, yg, x(k), y(k));
zg(~isin) = NaN;
contourf(xg,yg,zg);
3 comentarios
Kelly Kearney
el 26 de Ag. de 2015
The polygon shape you're seeing right now is based on the convex hull of your data points. If you want something different, you're going to have to find the appropriate way to calculate the boundary, and use that to mask your data (which is what I did with the convhull, inpolygon lines of the above code). Perhaps a bounding ellipse, perhaps something based on point density, etc. But at this point, you know your data and your final output requirements better than I do, so I can't help much.
Más respuestas (1)
John D'Errico
el 19 de Sept. de 2015
I just saw this question. I'll add a few comments as the author of gridfit, but I've already upvoted Kelly's response. I could have just put what I have to say in as a comment, but I hope that some of what I can say is worth reading, and might be easier to notice as an answer.
Gridfit will extrapolate to the limits of the nodes you give it. It attempts to do so smoothly. A delaunay based approach will only interpolate within the convex hull of the points. You cannot rationally expect them to yield the same results. Both methods are useful, valuable, and important, though usually on different problems.
Note that gridfit does have several methods for your use. Those who try to build a surface that may involve a great deal of extrapolation as it appears here, may do better with the 'springs' option for the regularizer in gridfit. That option was designed to be less aggressive about extrapolation. The fact is however, extrapolation over long distances is a terribly poor idea in general.
A method that works only on a convex hull cannot extrapolate well. As well, when your data is not fully convex, expect to see problems. Typically, one sees large triangles around the edges of the domain when the data is not convex. Then you should expect to see poor interpolation characteristics in those regions.
What is best is to understand every method one might use, and know when to use one tool or another. A good workman understands all of the tools in their toolbox, and knows when to use each of them to best advantage.
0 comentarios
Ver también
Categorías
Más información sobre Computational Geometry en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!