MATLAB: How to obtain the curved lines on the surface of ‘surf’ plot which generate the XY plane projections in ‘surfc’

MATLAB

Consider the following code:
f=@(x,y) (x.^2-y.^2)./(x.^2+y.^2);
[X,Y]=meshgrid(linspace(-1,1));
Z=f(X,Y);
surfc(X,Y,Z)
How can I replace the edge lines on a surface project on the XY plane with lines that run along the 'surf' plot generated, and which when projected in the XY plane, give the lines given by 'surfc'?

Best Answer

The curved lines along the 'surf' plot can be obtained for the case above by modifying and executing the code as below
f=@(x,y) (x.^2-y.^2)./(x.^2+y.^2);
[X,Y]=meshgrid(linspace(-1,1));
Z=f(X,Y);
[M,~] = contour(X,Y,Z);
x = M(1,:);
y = M(2,:);
z = f(x,y);
figure
surf(X,Y,Z), hold on
lims = axis;
scatter3(x,y,z, 'filled', 'MarkerFaceColor', 'r'), hold off
axis(lims)