Creating 2D contours from XYZ values
41 次查看(过去 30 天)
显示 更早的评论
I need to create a 2D contour map from the following X,Y,Z values:
x =
62158.9992780663
-60909.305073411
-66390.9511725443
39368.6900415121
51352.5822375015
-21369.5783460914
-87076.7531674554
49625.0647256742
38699.5563685481
52310.578005926
-66729.7609269372
y =
-464698.41308258
316839.903892009
298087.560112334
-499661.758015527
298806.606131584
129251.742701853
256843.382855648
-367726.4174525
-566816.147075169
320336.240040152
278737.299892196
z =
266.712
37.838
7.79
301.42
145.949
145.305
112.418
289.788
268.437
-10.679
201.505
The X and Y values are grid coordinates. The Z values are ellipsoidal heights in metres.
I tried using the following code:
contour(x,y,z)
And I get this error:
Error using contour (line 48)
Z must be at least a 2x2 matrix.
Error in Contours (line 284)
contour(x,y,z)
Can anyone help me create a contour map with contour lines every 10m?
0 个评论
采纳的回答
Star Strider
2020-5-18
This is likely the best you can do:
xv = linspace(min(x), max(x), numel(x));
yv = linspace(min(y), max(y), numel(y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym);
figure
contourf(Xm, Ym, Zm)
grid
This creates monotonically-increading vectors from the original ‘x’ and ‘y’ vectors using linspace, creates corresponding matrices using ndgrid, then interpolates them using griddata to create the matrices necessary for the contour function. (The grid call is optional.)
5 个评论
Star Strider
2020-5-31
If I remember correctly, the blank areas are because griddata is extrapolating, and except for the 'v4' method, extrapolated values are NaN and so don’t plot. Experiment with 'v4' to see if it does what you want. See the documentation section on method for details.
If there is a Mapping Toolbox function that approximates this, it may be preferable to griddata. I don’t have the Mapping Toolbox, so I can’t determine that.
更多回答(1 个)
KSSV
2020-5-18
Read about delaunayTriangulation. And then use this https://in.mathworks.com/matlabcentral/fileexchange/38858-contour-plot-for-scattered-data?focused=5249779&tab=function
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!