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?

采纳的回答

Star Strider
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 个评论
Wesley Brown
Wesley Brown 2020-5-31
I am wondering if there is any way to ensure that the contour map goes to the extents of the project area? I'm needing the contour map to continue out to the + marks I've plotted. The plus marks are X and Y coordinates above.
Star Strider
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
KSSV 2020-5-18
  1 个评论
Wesley Brown
Wesley Brown 2020-5-19
I found this link very confusing. I like the way tricontour looks but I can't figure it out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by