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!