Unable to get similar contour using the gridfit

7 views (last 30 days)
sanjeet
sanjeet on 21 Aug 2015
Answered: John D'Errico on 19 Sep 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);
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)

Accepted Answer

Kelly Kearney
Kelly Kearney on 24 Aug 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 Comments
sanjeet
sanjeet on 19 Sep 2015
I have updated points x and y for covexhull() , but the polygon shpae is not as per the distribution of points its more regular.
Is there way to change the convexhull output as more spray like

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 19 Sep 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.

Community Treasure Hunt

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

Start Hunting!