正如@SardarUsama指出的那样, plot3 应该做的伎俩。代码可以更紧凑但保持清晰。
plot3
MATLAB 2017a
x = [0,0,0,0,0,10,10,10,10,10]; y = [0,10,20,30,40,-10,0,10,20,30]; z = [46,52,51,59,53,85,56,87,86,88]; figure scatter3(x, y, z, 30, 'filled') % scatter plot (3D) zRng = zlim; hold on for k = 1:length(x) xL = [x(k) x(k)]; yL = [y(k) y(k)]; zL = [zRng(1) z(k)]; plot3(xL,yL,zL,'r-') % plot vertical line (3D) end