How to extract a 2D surface from a 3D data set?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a 3D array, T, which has (Nx,Ny,Nz) elements. It contains the temperature of some fluid dynamical system.
I know ahead of time that there is some cylindrical symmetry in the data. As a result, there is some utility in extracting a cylindrical shell surface from the data, which could be contained in a single 2D array (only variables are theta - azimuth - and z).
Currently, I do this using a large loop (code at the bottom). This is obviously quite slow since I am interpolating at every z slice. Is there a way to do this without several loops? Perhaps using interp3?
One idea I had was to try
xcoord = rnow.*sin(theta);
ycoord = rnow.*sin(theta);
z1d = Z(1,1,:);
tprof = interp3(X,Y,Z,tnow,xcoord,ycoord,z1d,'spline');
The problem would be that if this worked, then tprof is just a different 3D array on the new grid. Essentially a cylindrical shell in cartesian coordinates. If this works, how can I convert it to cylindrical coordinates and then remove the radial component (since it would be contant with r)?
num_points = 1000;
%Dimensions
Lx = 1;
Ly = 2;
Lz = 1.2;
%Number of grid points
Nx = 50;
Ny = 100;
Nz = 20;
%Calculate x,y,z grid
x1d = linspace(0,Lx,Nx);
y1d = linspace(0,Ly,Ny);
z1d = linspace(0,Lz,Nz);
[X,Y,Z] = meshgrid(x1d,y1d,z1d);
%Example field
Data = X.^3+2.*Y-Z;
%Azimuthal angle in polar coordinates
%Origin is at Data(1,1,1)
theta = linspace(0,pi/2,num_points);
rnow = 1;
for AzimuthalPoint = 2:num_points
% Calculate the angle along the arc of r = rnow
% Calculate the corresponding y-coordinate
ycoord = rnow * sin(theta(AzimuthalPoint));
xcoord = rnow * cos(theta(AzimuthalPoint));
for VertPoint = 1:Nz
% Find the temperature at the radius r = rnow by interpolating tnow1d
% using spline interpolation
tprof(AzimuthalPoint,VertPoint) = interp2(x1d, y1d, Data(:,:,VertPoint), xcoord, ycoord, 'spline');
end
end
0 comentarios
Respuestas (1)
Supraja
el 27 de Jul. de 2023
I understand that you want to convert your coordinates to cylindrical then remove the radial component from it.
To convert the coordinates from cylindrical to 2 D matrix by removing the radial component, you can use the “squeeze” function in MATLAB. The detailed documentation link for the function is attached is here: https://www.mathworks.com/help/matlab/ref/squeeze.html
For the initial part of conversion of coordinates to cylindrical system, you can mathematical equations.
Hope this works!
1 comentario
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!