Trying to create a filled colour contour plot. Specifically in the form of a depth profile.

3 views (last 30 days)
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 Comments
Joshua
Joshua on 4 Mar 2011
scatter(x,z) does now give a graph, sorry, possibly as a result of clearing some previous code.

Sign in to comment.

Accepted Answer

Matt Tearle
Matt Tearle on 4 Mar 2011
For an older version of MATLAB (without TriScatterdInterp):
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
[qx,qy] = meshgrid(linspace(min(x),max(x)),linspace(min(y),max(y)));
qz = griddata(x,y,z,qx,qy);
contourf(qx,qy,qz)
  11 Comments
Matt Tearle
Matt Tearle on 5 Mar 2011
??? Why are you using contourf on the original data?
% load x y z data
[qx,qy] = meshgrid(linspace(min(x),max(x)),linspace(min(y),max(y)));
qz = griddata(x,y,z,qx,qy);
contourf(qx,qy,qz)
Works fine for me, using the x, y, z values you've posted.

Sign in to comment.

More Answers (1)

Matt Tearle
Matt Tearle on 3 Mar 2011
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 Comments
Joshua
Joshua on 4 Mar 2011
it still says:
??? Undefined command/function 'TriScatteredInterp'.
Error in ==> a at 7
F = TriScatteredInterp(x,y,z);

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!