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

contourMATLAB

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?

Best Answer

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)