MATLAB: How do you make vertical lines from the boundary plane of a plot to connect to the corners of its surface

3d plotshelp

Here is the code for the plot
figure
axes
xv = linspace(log(5e5), log(1e7), 100);
yv = linspace(log(0.6), log(2000), 100);
[X, Y] = meshgrid(xv, yv);
Z = log((0.037 .* (X.^0.8) .* Y )./ (1 + 2.443 .* (X .^ -0.1) .* (Y .^ (2/3) - 1)));
mesh(X, Y, real(Z));
grid on

Best Answer

  • Get corners of the surface and Z-values in those points
  • Use plot3 to plot the four lines
figure;hold on
xv = linspace(5e5,1e7,100);
yv = linspace(0.6, 200, 100);
[X, Y] = meshgrid(xv, yv);
Z = (0.037 .* (X.^0.8) .* Y )./ (1 + 2.443 .* (X .^ -0.1) .* (Y .^ (2/3) - 1));
h=surf(log10(X), log10(Y), real(log10(Z)),'facecolor','interp','EdgeColor','none');
xlabel('Re'),ylabel('Pr'),zlabel('Nu');
%%Define Z-limits
zl=[2 6]; %Define Z limit
%%Define corners
Xc=[X(1,1) X(1,end) X(end,1) X(end,end)];
Yc=[Y(1,1) Y(1,end) Y(end,1) Y(end,end)];
Zc=[Z(1,1) Z(1,end) Z(end,1) Z(end,end)];
Z0=[zl(1) zl(1) zl(1) zl(1)];
%%Plot
for i=1:4;
hline(i)=plot3(log10([Xc(i) Xc(i)]),log10([Yc(i) Yc(i)]),[real(log10(Zc(i))) Z0(i)],'k')
end
view(3)
grid on
set(h,'facealpha',0.7)
set(gca,'zlim',zl)
set(hline,'linewidth',2)
set(hline(4),'linestyle','--')
The coordinates of the corners are defined from the max/min of the grid. This means that the lines will appear outside of the plot if you do not display the entire grid, by e.g. reducing the x- or y-limits. If you only want to display part of the plot, reduce the grid size instead.