plot contour line of three variable ?

1 次查看(过去 30 天)
Hi I have thistext file ( please see attached )with 3 columns ( lat, lon and depth ) I want to plot a contour map of the water depth as a function of lat and lon. I used the following code contour (lat,lon,depth) where I extracted lat, lon, and depth separately but I get this error "Z must be at least a 2x2 matrix."
any help ? thanks

回答(2 个)

Star Strider
Star Strider 2017-12-20
编辑:Star Strider 2017-12-20
If the file is very large, probably the easiest way to see if your data are gridded (such that the ‘x’ and ‘y’ values repeat in a specific, regular pattern) is to plot your vectors using the stem3 function. If they appear to be regularly-spaced, you can use the reshape function to form them into matrices. Then you can use your matrices with contour.
If they are not gridded, you will have to interpolate them to be gridded matrices. See the griddata (link) function and its friends to do that.
EDIT
If ‘M’ is your (Nx3) matrix:
x = linspace(min(M(:,1)), max(M(:,1)), size(M,1)+1);
y = linspace(min(M(:,2)), max(M(:,2)), size(M,1)+1);
[X,Y] = meshgrid(x, y);
Z = griddata(M(:,1), M(:,2), M(:,3), X, Y);
figure(1)
contourf(X, Y, Z)
axis equal
grid
Experiment to get the result you want.
  1 个评论
Akim Mahmud
Akim Mahmud 2017-12-20
I am not sure, if I follow you correctly. I am still new to matlab. I have attached a sample txt from the big txt file. I have used the stem2 function to see the data I am not sure how to use reshape function to from them into matrices. Any help would be appreciated

请先登录,再进行评论。


Harshana Rajakaruna
Thanks

类别

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