TriScatteredInterp not interpolating as expected?
Show older comments
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));
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!