MATLAB: How to plot a surface without the ends “connected”

3d plot3d scatterMATLABmeshgridplotscattersurfsurface plotxyz

After having used this tutorial to perform a surface plot for data in x,y, and z, MATLAB connects the ends of the data.
This can be seen by the flat, blue surface at the bottom of my plot. What can I do to stop it from connecting the ends?
My code is as follows:
%% Importing excel data
filename = 'ansysexport.xlsx';
p = xlsread(filename,2);
t = xlsread(filename,3);
v = xlsread(filename,4);
%% Velocity
vx=v(5:2495,1);
vy=v(5:2495,2);
vz=v(5:2495,3);
[VX,VY] = meshgrid(vx,vy);
VZ = griddata(vx,vy,vz,VX,VY,'cubic');
set(gcf,'renderer','zbuffer')
surf(VX,VY,VZ);
xlabel('X');
ylabel('Z');
zlabel('Velocity (m/s)');
set(gca,'FontSize',30)
lighting phong
colorbar EastOutside

Best Answer

I think the issue is your X data is cyclical. The approach you are taking seems to be over-complicating the issue. I think you can solve your issue much easier by taking advantage of the cyclical nature of your data with the following:
  1. Don't pull in all values in vx. Just pull in one set of the values that repeat.
  2. Don't pull in all values in vy. Just pull in the unique values.
  3. Don't need to meshgrid your vx and vy anymore, though you can if you want to.
  4. Don't use griddata on vz. Instead, use reshape to make the existing Z data align with vx and vy.
I believe this works, and it greatly reduces the size of your surf so it's easier to use.
vx = v(1:50,1);
vy = unique(v(:,2));
vz = reshape(v(:,3),length(vx),length(vy));
surf(vx,vy,vz)
% so that you can see the bottom is gone
view([-300 20])
surf_Fixed.png
The back wall is your t=0 wall. You can remove it by modifying the data you send to surf:
surf(vx(2:end),vy,vz(:,2:end))
surf_Fixed2.png
Related Question