Calculate 3D gradient of data corrisponding to a non-uniform grid

3 次查看(过去 30 天)
Hi all,
In order to obtain a spherical 3D grid, I have generated an evenly-spaced azimuth-elevation-radius ndgrid and subsequently transformed it in cartesian coordinates using sph2cart. In this coordinates system, points are not evenly spaced.
[AZ_grid,EL_grid,R_grid]=ndgrid(AZ_vector,EL_vector,R_vector); % evenly spaced 3D grid
[X_grid,Y_grid,Z_grid]=sph2cart(AZ_grid,EL_grid,R_grid); %non-evenly spaced 3D grid
I have a 3D matrix P of values corresponding to these points in space. Obviously, if X_grid=[NxMxH], also P=[NxMxH].
I have to calculate the gradient of P along every direction. For the spherical case, I think I could write:
[G_AZ,G_EL,G_R]=gradient(P,AZ_spacing,EL_spacing,R_spacing);
as AZ_spacing,EL_spacing,R_spacing are constants.
How can I get the same result in cartesian coordinates (without using scatteredInterpolant or similar as it does not support code generation)? I tried to transform G_AZ,G_EL,G_R using sph2cart (as below), but I'm not sure the results obtained are the correct ones.
[GX,GY,GZ]=sph2cart(G_AZ,G_EL,G_R);
Thanks to anyone who can help me!

采纳的回答

Matt J
Matt J 2023-3-26
编辑:Matt J 2023-3-26
I would just compute the Jacobian matrix of the spherical to cartesian coordinate transformation and multiply the spherical gradients by that.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by