Filter löschen
Filter löschen

TriScatteredInterp not interpolating as expected?

3 Ansichten (letzte 30 Tage)
Bruno Rodriguez
Bruno Rodriguez am 5 Sep. 2017
Bearbeitet: Bruno Rodriguez am 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));

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
Bruno Rodriguez
Bruno Rodriguez am 5 Sep. 2017
So if I understand correctly, it is overriding those "z" that DO lie within the range of heights? If so, I take it I need to limit my range of Z. However, for every x-coord, the range of heights I need interpolated differs, so I would not have a rectangular array...any idea how I could get around that?
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolating Gridded Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by