Compare closest grid cells without interpolation

1 回表示 (過去 30 日間)
Melissa
Melissa 2015 年 3 月 7 日
コメント済み: Melissa 2015 年 3 月 15 日
Hello,
I want to compare two global data sets that do not share the same resolution. I want to compare the values with each other at the closest grid cells to each other. Is there any way to do with without interpolation?
Thank you,
Melissa

回答 (1 件)

arich82
arich82 2015 年 3 月 7 日
I realize you said you don't want interpolation, but have you considered interp2 with the 'nearest' method? It really seems appropriate here...
Assuming you have a coarse 2-D grid X_coarse, Y_coarse with data V_coarse, and a fine 2-D grid X_fine, Y_fine with data V_fine, you could use something like
V_compare = interp2(X_coarse, Y_coarse, V_coarse, X_fine, Y_fine, 'nearest');
then compare V_compare to V_fine. (Obviously, you could also swap all of the _fine and _coarse variables if you wanted to compare the other way around.)
Note that there are equivalent functions interp1, interp3, and interpn which support the 'nearest' method, if your grid isn't 2-D.
If the default Matlab interp family isn't fast enough, there might be faster implementations on the File Exchange. You might also look into Matlab's griddedInterpolant class with the 'nearest' method, if you have a fairly recent version.
Otherwise, if you're truly opposed to a 'nearest' interpolation scheme, you're probably stuck trying to use a k-D tree search algorithm.
Does the interp function meet your requirements?
--Andy
  2 件のコメント
arich82
arich82 2015 年 3 月 7 日
Before you go down the path of a k-D tree, I should add that if one of your grids is regular, you might be able to find the corresponding grid point explicitly using index arithmetic.
There's also a fairly simple solution using histc.
A little more detail on the dimensionality of your data, and the regularity of your grids would be helpful if interpn(..., 'nearest') doesn't suit your needs.
Melissa
Melissa 2015 年 3 月 15 日
Hi Andy,
I'm trying to acquire the nearest datapoint from the world harmonized soil database, which is 7200x3600 (lonxlat) compared to my dataset A with lat (471x1), lon (471x1) and biomass (471x1). A is not in 2 dimensional form, but is instead 3 vectors of lat, lon, and biomass. Since A is so sparse, I only want to get the datapoint in the harmonized soil database closest to the datapoint in A. I'm not really sure how to use interp2 in this case, since A is not in 2 dimensional form like the world harmonized database is.
Any ideas?
-Melissa

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by