How can I plot a surface without the ends "connected"?

조회 수: 18 (최근 30일)
Calvin D'Souza
Calvin D'Souza 2018년 12월 6일
편집: Cris LaPierre 2018년 12월 7일
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

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 12월 7일
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
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2018년 12월 7일
편집: Cris LaPierre 2018년 12월 7일
You could also get the unique values for x.
vx = unique(v(:,1));
It gets the same data, but it just 'feels' better to me to grab a complete set like I did.
Calvin D'Souza
Calvin D'Souza 2018년 12월 7일
Thanks a lot Cris! The tutorial I followed made my data a lot more complicated than it needed to be. Your approach works really well.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by