Trying to create a filled colour contour plot. Specifically in the form of a depth profile.
古いコメントを表示
Hello, I am trying to create a depth profile of a stretch of water, with X being Distance, Y being Depth and Z being the coloured fill for Salinity.
I've found it possible to create an X-Y plot of the depth and distance but can't figure how to add the Z and get it as the coloured fill.
I have however already looked at the graph tools section and inputted x, y and z variable inputs, but it still only gives me a graph of x or y.
FYI. each variable was originally in one variable ('num') but i have since seperated into 'Distance','Depth','Salinity'. Also all columns have data of the same length (1;332). Can anyone help me?
10 件のコメント
Walter Roberson
2011 年 3 月 2 日
Are your X and Y over grid, or are they scattered ?
Joshua
2011 年 3 月 3 日
Sarah Wait Zaranek
2011 年 3 月 3 日
Do you want a filled contour plot (aka contourf)? Or plots x vs y with z being the color of the points (scatter(x,y,z)? Or something else?
Joshua
2011 年 3 月 4 日
Walter Roberson
2011 年 3 月 4 日
Please double check that z is the same size and shape as x and y.
You could try scatter3(x,y,z) if the sizes are the same
Matt Tearle
2011 年 3 月 4 日
What are the sizes returned by:
whos x y z
Joshua
2011 年 3 月 4 日
Joshua
2011 年 3 月 4 日
Matt Tearle
2011 年 3 月 4 日
but scatter(x,z) gives an error? what is the error message?
Joshua
2011 年 3 月 4 日
採用された回答
その他の回答 (1 件)
Matt Tearle
2011 年 3 月 3 日
Something like this, perhaps:
% invent some x,y,z data
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
% interpolate onto regular grid
F = TriScatteredInterp(x,y,z);
[qx,qy] = meshgrid(linspace(min(x),max(x)),linspace(min(y),max(y)));
qz = F(qx,qy);
% filled contour plot
contourf(qx,qy,qz)
5 件のコメント
Sarah Wait Zaranek
2011 年 3 月 3 日
Exactly what I was thinking, Matt.
Joshua
2011 年 3 月 4 日
Matt Tearle
2011 年 3 月 4 日
Ah, I'm guessing you have an old version of MATLAB? In that case, delete that line (obviously), and replace "qz = F(...)" with
qz = griddata(x,y,z,qx,qy);
Joshua
2011 年 3 月 4 日
Matt Tearle
2011 年 3 月 4 日
Delete that line. See new answer for the full code
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!