2D circular interpolation (theta, phi) angles

22 Ansichten (letzte 30 Tage)
Albert
Albert am 3 Aug. 2021
Hi, I have a 2D matrix Z that is function of theta and phi coordinates Z(theta,phi). I have a regular grid of theta and phi coordinates along with the value of Z. Then, I have some scattered points theta_i and phi_i for which I want to interpolate the value of Z. This I can do it easily by doing:
Z_i = interp2(theta,phi,Z);
However, the sampling of matrix Z is limited. For example, if the theta and phi step is 1 degree (then theta from 0:1:179 and phi 0:1:359), it may happen that a valid scattered point falls at one edge of the sampling. For instance a point (theta_i,phi_i) = (0,359.5) will raise a NaN during interp2 because it does not know how to interpolate. Due to the circular symmetry of (theta, phi) angles in fact Z(0,360) = Z(0,0) so that all information needed for interpolation is there, however how can I make interp2 make aware of this angular symmetry? I realized using 'spline' actually provides a valid number, however I would prefer not to use it. Thanks!

Akzeptierte Antwort

Bjorn Gustavsson
Bjorn Gustavsson am 3 Aug. 2021
Simply concatenate the Z-values for columns and rows corresponding to theta and phi equal 0 and 1 at the end of Z and extend the range of theta and phi to 0:181 and 0:361. (You might also consider extending to negative angles):
Znew = Z([end-1:end,1:end,1:2],[end-1:end,1:end,1:2]);
theta_new = -2:181;
phi_new = -2:361;
The reason to extend beyond 0-360 is that this ensure periodicity even for the different spline-interpolation methods (I think this is a sufficient number of points added even for 'cubic' interpolation).
HTH
  2 Kommentare
Albert
Albert am 3 Aug. 2021
Great, yes adding this extra point at each side works. thanks!
Bjorn Gustavsson
Bjorn Gustavsson am 3 Aug. 2021
Good, happy that it solved your problem.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by