TriScatteredInterp not interpolating as expected?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bruno Rodriguez
le 5 Sep 2017
Modifié(e) : Bruno Rodriguez
le 7 Sep 2017
I tried to interpolate a set of radar reflectivity values using TriScatteredInterp (and later with scatteredInterpolant). As my initial data had quite a few NaN values, the final interpolation incorrectly created an entire array of NaNs. I tried repeating the interpolation by subbing "-50" in for the NaNs (I can erase bad data after), but when I do that, TriScatterdInterp still returns an antire array of NaNs, and scatteredInterpolant fills the entire array with -50, which is also incorrect. The data and code has been attached. Any ideas what may be wrong?
(I tested it out on a small sample of test data and it worked, but still returns all NaNs or all -50 when I apply it to my dataset).
"initial_heights.m" = z_radar_dn in code. "original_dbz.m" = dbz_dn_sub_thresh in code.
% Prep input arrays
heights = z_radar_dn(:,:)';
x = 1:4443;
x = repmat(x,413,1);
dbz_initial = dbz_dn_sub_thresh(:,:)';
dbz = dbz_initial;
% Replace NaN's with -50 for interpolation
replace = isnan(dbz);
dbz(replace) = -50;
% Flatten to vectors
%F_ref = scatteredInterpolant(double(x(:)),double(heights(:)),double(dbz(:)));
F_ref = TriScatteredInterp(double(x(:)),double(heights(:)),double(dbz(:)));
% Set up a perfect grid
xvec = [1:4443];
maxHeight = max(z_radar_dn(1,:))*1000;
n = floor(maxHeight/30);
zvec = [maxHeight:-30:maxHeight-(n*30)];
% Mesh them together
[xmat,zmat]=meshgrid(xvec,zvec);
% Interpolate
dbz_interpolated= F_ref(xmat(:),double(zmat(:)));
% Reshape
dbz_interpolated=reshape(dbz_interpolated, size(xmat));
0 commentaires
Réponse acceptée
Walter Roberson
le 5 Sep 2017
When you create the interpolant the second variable corresponding to y is your height variable. When you go to use the interpolant you are passing z as the second variable. Most of your z are not in the same range as your height so the interpolant is applying its default extrapolation of putting in nan.
2 commentaires
Walter Roberson
le 6 Sep 2017
Each time you call
F = scatteredInterpolant(x, y, z)
you create a function F . You have to pass x and y coordinates to that function to get z outputs. But that isn't what you did. You passed in x and z instead.
The x and y that you pass in to the function do not need to be equally spaced. If you pass in vectors (of equal length) then only the points you indicate will be interpolated.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolating Gridded Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!