Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
AleF
AleF le 26 Mar 2023
Commenté : AleF le 27 Mar 2023
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!

Réponse acceptée

Matt J
Matt J le 26 Mar 2023
Modifié(e) : Matt J le 26 Mar 2023
I would just compute the Jacobian matrix of the spherical to cartesian coordinate transformation and multiply the spherical gradients by that.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by