Why my grid data always show a zero by zero dimension?
4 次查看(过去 30 天)
显示 更早的评论
I want to plot contourf and for that I need to create grid data but it always shows a zero by zero dimesion.
Lat=1:1:100;
Long=201:1:300;
Elv=151:1:250
[xg yg] = meshgrid(Lat,Long);
zg = griddata(Lat,Long,Elv,xg,yg);
contourf(xg,yg,zg);
1 个评论
Bjorn Gustavsson
2022-3-21
This looks like you have Elv-data along a line in Lat-Long and then tries to extrapolate the Elv (elevation?) out into a rectangular Lat-Long regio. Since griddata works with a Delaunay-triangulation (unless you specify the 'v4' method that is slightly different in a way that doesn't help you here) it requires at least one point to be off of that line to be able to produce any triangles, and these triangulations work best for interpolation inside the sensible convex boundary of the Lat-Long-points, while peculiar things often happen when one tries to extrapolate. This gives us another way to look at why you run into problems - you dont really have much of a convex hull to your points when they are co-linear.
In this situation you might just as well simply assume that your points lie on a plane with the normal in the Lat-Long-points-and-vertical plane but perpendicular to that elevation-line?
回答(1 个)
Ishu
2023-11-26
Hi Muhammad Qaisar Fahim,
I understand that you are trying to interpolate the data onto a grid using "griddata" but you are getting "zg" as empty.
If you try to run this code upto "zg" you will get a warning that "The underlying triangulation is empty - the points may be collinear". It is just that your input data is collinear that is why "griddata" is not able to interpolate the data, as a result you are getting "zg" as empty.
You can try by changing your "Lat" and "Long" data like I have shown below.
Lat=1:0.3:30.8;
Long=201:1.5:350;
Elv=151:1:250;
[xg, yg] = meshgrid(Lat,Long);
zg = griddata(Lat,Long,Elv,xg,yg)
For more information you can read below MathWorks documentation:
Hope it helps.
1 个评论
DGM
2023-11-26
编辑:DGM
2023-11-26
How is this an answer to the question?
You've presupposed different data. That's not generally an option.
The sample locations are still colinear. The only thing that this particular data selection does is introduce small rounding error that causes the points to not be treated as colinear even though they still are nominally colinear. It would be less presumptuous to merely add a tiny amount of gaussian noise to the original data instead of conjuring up entirely new unrelated data.
Either way, the result is still useless for the intended purpose. It's still just a vector. Elv is now merely diag(zg). That's it. No triangulation or interpolation or extrapolation has occurred. It's still degenerate. It's still a surface of zero area. There still is no point feeding it to contour(), because there's nothing to show.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!