필터 지우기
필터 지우기

TriScatteredInterp not interpolating as expected?

조회 수: 3 (최근 30일)
Bruno Rodriguez
Bruno Rodriguez 2017년 9월 5일
편집: Bruno Rodriguez 2017년 9월 7일
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));

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 5일
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
Bruno Rodriguez
Bruno Rodriguez 2017년 9월 5일
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 2017년 9월 6일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolating Gridded Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by