You could use contour or contourc or contour3 for what you want, but this is much more challenging than you think. Consider a 3D plane or 3D curve without any discontinuities: for some Z on that plane/curve, there could be infinite X and Y values that have the same Z value: these are the contours of that plane/curve. In some degenerate cases there may be only one X or Y value. So which if those infinite/one X and Y values do you want? Think about contours, and then think about how such results could possibly be encoded or returned. Read the contour and contourc help. Read about the contour matrix:
Here is a simple example of how it works:
[X,Y,Z] = peaks(25);
surf(X,Y,Z)
Xg = X(1,:);
Yg = Y(:,1);
hold on
M = contour3(Xg,Yg,Z,[5,5],'*-r');
fun = @(s,v)fprintf('%s %s\n',s,sprintf(' %5.2f',v));
fun('Xg',Xg)
fun('Yg',Yg)
fun('Xc',M(1,2:end))
fun('Yc',M(2,2:end))
Original grid:
Xv -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00
Yv -3.00 -2.75 -2.50 -2.25 -2.00 -1.75 -1.50 -1.25 -1.00 -0.75 -0.50 -0.25 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00
Contour matrix for Z==5:
Xc -0.48 -0.25 0.00 0.25 0.50 0.50 0.70 0.66 0.50 0.38 0.25 0.00 -0.25 -0.38 -0.50 -0.64 -0.66 -0.50 -0.48
Yc 1.25 1.14 1.12 1.16 1.25 1.25 1.50 1.75 1.92 2.00 2.06 2.10 2.06 2.00 1.92 1.75 1.50 1.27 1.25
The contour for Z==5 is plotted in red:
Best Answer