Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading