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

6 vues (au cours des 30 derniers jours)
Daniel
Daniel le 17 Juin 2020
Modifié(e) : darova le 24 Juin 2020
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 commentaires
Daniel
Daniel le 18 Juin 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?

Connectez-vous pour commenter.

Réponse acceptée

darova
darova le 20 Juin 2020
Modifié(e) : darova le 24 Juin 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 commentaires
darova
darova le 23 Juin 2020
Use griddata to calculate 3D matrices
Daniel
Daniel le 23 Juin 2020
I think griddata is the best solution so far. If you'd like to edit your "answer", I can mark it as correct.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by