简体   繁体   中英

Gap in MATLAB surface plot

I'm trying to plot a cone in MATLAB using the following code. However, when MATLAB generates the plot, there is a gap in the surface as shown in the image below. Would anyone be able to suggest a way to close it?

clearvars; close all; clc;

[theta, r] = meshgrid(-pi:0.1:pi, -4:0.1:6);
x = (r-1).*cos(theta);
y = (r-1).*sin(theta);
z = r;

% 3-D plot
figure
surf(x, y, z);
xlabel("x"); ylabel("y"); zlabel("z");
zlim([0 8]);
axis square

在此处输入图像描述

The problem is that the list of theta stops before reaching pi because the increments of 0.1 do not reach the upper bound.

For example, you may use the line

[theta, r] = meshgrid(-pi:(2*pi/20):pi, -4:0.1:6);

to complete the circle in 20 steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM