MATLAB: How to project a 3-D surface onto an axis

2d3dflatprojectionsurfacewall

I would like to generate a projection of a surface on one axis. For example, I wish to see the x-z axis of a 3-D view of a surface. What MATLAB commands allow me to do this?

Best Answer

This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
[X,Y] = meshgrid([-2:.2:2]);
Z = X.*exp(-X.^2-Y.^2);
surf(X,Y,Z,gradient(Z)) % An example of 3D plot
colorbar
xlabel('X-AXIS')
ylabel('Y-AXIS')
zlabel('Z-AXIS')
axis([-2 2 -2 3 -0.5 0.5]) % Increasing the Ymax value in the axis to 3.
SX=size(X);
Y3 = 3*ones(SX); % A projection along Y-axis by making all Y-values to 3.
hold on
surf(X,Y3,Z,gradient(Z))