plot contour line of three variable ?

2 ビュー (過去 30 日間)
Akim Mahmud
Akim Mahmud 2017 年 12 月 20 日
回答済み: Harshana Rajakaruna 2018 年 3 月 15 日
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
Harshana Rajakaruna 2018 年 3 月 15 日
Thanks

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by