Interpolate to plot contour in plane of non-uniform 3D data
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
darova
am 20 Jun. 2020
Bearbeitet: darova
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!