필터 지우기
필터 지우기

plot contour line of three variable ?

조회 수: 1 (최근 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 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