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

4 views (last 30 days)
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 Comments
Daniel
Daniel on 18 Jun 2020
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?

Sign in to comment.

Accepted Answer

darova
darova on 20 Jun 2020
Edited: darova on 24 Jun 2020
  • 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 Comments
Daniel
Daniel on 23 Jun 2020
I think griddata is the best solution so far. If you'd like to edit your "answer", I can mark it as correct.

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!