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 Center および File ExchangeSurface 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