Given 3 vector-pair, X
, Y
and Z
, how to generate the contour? I understand that we need to make use of the contour plot. But the thing
Yes. Use the Tricontour tool. It is found on the file exchange (on Matlab Central.) This does the contouring as you desire directly, without forcing you to use meshgrid and griddata.
MATLAB addresses this need of yours fairly succinctly.
What you need to do is use meshgrid
to two-dimensionalize your X
and Y
vectors. Here is a simple example to demonstrate how to generate a contour plot of z = sin (x^2 + x*y^2)
:
x = -10:0.1:10;
y = -10:0.1:10;
[x,y] = meshgrid(x,y);
z = sin(x.^2+x.*y.^2);
contour(x,y,z)
Note the use of the .^
and .*
notations, which forces MATLAB to conduct an element-by-element evaluation of the z
matrix, making it 2D in the process.