Home > Software design >  Gap in MATLAB surface plot
Gap in MATLAB surface plot

Time:09-04

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

enter image description here

CodePudding user response:

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.

  • Related