Interpolate to plot contour in plane of non-uniform 3D data

조회 수: 6 (최근 30일)
Daniel
Daniel 2020년 6월 17일
편집: darova 2020년 6월 24일
I have a set of three dimensional data (attached) that is on a non-uniform grid. In the code below, you see how I load, reshape, and plot to get an accurate 3D representation.
clear; close all
data = xlsread('C:\PATH\V27TestOutputCelementCV27_WakeElemData_00206.csv');
node = data(:,2);
orgn = data(:,3);
xr = data(:,4);
yr = data(:,5);
zr = data(:,6);
uu = data(:,7);
vu = data(:,8);
wu = data(:,9);
m = length(orgn(orgn==1)); % the input file is sorted by origin node, so use it to reshape
n = orgn(end);
x = reshape(xr,[m,n]); % each column is a different origin node now
y = reshape(yr,[m,n]);
z = reshape(zr,[m,n]);
u = reshape(uu,[m,n]);
v = reshape(vu,[m,n]);
w = reshape(wu,[m,n]);
quiver3(x,y,z,u,v,w), xlabel('x/R'), ylabel('y/R'), zlabel('z/R')
I've looked around, but I can't figure out how I can create a grid, do some interpolating, and plot a contour slice of this data. For example, how would I plot a contour showing the u data along y = 0 for all x and z?
UPDATE
I got some of it with this:
F = scatteredInterpolant(xr,yr,zr,uu);
[xq,yq,zq] = meshgrid(-1:0.05:8,-1.5:0.5:1.5,-1.5:0.05:1.5);
uq = F(xq,yq,zq);
figure, contourf(squeeze(uq(4,:,:))'), colorbar
The data is new to me, but I think this looks "right". One thing that I'm not getting right is using x and y in contourf to get the axes scaled correctly. I tried contourf(squeeze(xq(4,:,:))',squeeze(yq(4,:,:))',squeeze(uq(4,:,:))'), but this produced a line. I'm missing something... Also, if there are better ways, I'm still interested.
  댓글 수: 3
Daniel
Daniel 2020년 6월 18일
Slice is helpful, but a couple questions:
To get a 3D array of V, or in my case, u, I already interpolated it, didn't I? I guess I'm not clear on what scatteredInterpolant did, but I want to be sure I'm not interpolating twice since slice also interpolates. Second, is there a way to turn off the grid lines in the slice planes?

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

채택된 답변

darova
darova 2020년 6월 20일
편집: darova 2020년 6월 24일
  • Use griddata to interpolate your data (create 3d matrices)
  • Use slice to create crossection views
x = 2*rand(5000,1)-1;
y = 2*rand(5000,1)-1;
z = 2*rand(5000,1)-1;
v = x.^2 + y.^2 + z.^2;
[xq,yq,zq] = meshgrid(-1:0.1:1);
vq = griddata(x,y,z,v,xq,yq,zq);
plot3(x,y,z,'.r')
slice(xq,yq,zq,vq,[-1 1]/2,[-1 1]/2 ,[])
axis vis3d
  댓글 수: 3
darova
darova 2020년 6월 23일
Use griddata to calculate 3D matrices
Daniel
Daniel 2020년 6월 23일
I think griddata is the best solution so far. If you'd like to edit your "answer", I can mark it as correct.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by