How to compare lat lon from text file with netcdf file?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
I am trying to extract data based on lat lon values (it's a netcdf file). Before doing this step I need to compare lat lon values from 2 datasets.
I have a text file that contains 2 columns (lat and lon) as shown below:
lat lon
39.74 132.01
13.38 126.41
24.28 127.22
lat lon from netcdf file was in the form of column vector. So, I used meshgrid:
M_lat = ncread(fname, 'lat');
M_lon = ncread(fname, 'lon');
[X,Y] = meshgrid(M_lon, M_lat);
Now lat has become: (same goes for longitude)

Problem is my lat in text file is 39.74 and values in netcdf are 39.5 and 40. What is the possible solution for this kind of issue?
Based on index I need to extract data from my netcdf file. Thank you
0 件のコメント
回答 (1 件)
KSSV
2022 年 2 月 28 日
REad about interp2. You can do the interpolation and extract your required data.
data2 = interp2(X1,Y1,data1,X2,Y2) ;
% where X1, Y1, data1 are from netcdf
% X2, Y2 is your grid from text file
If you don't want to do interpolation; you can get the nearest points using knnsearch and extract the data by indexing.
4 件のコメント
KSSV
2022 年 2 月 28 日
[m1,n1,p1] = size(data2) ;
[m2,n2] = size(X2) ;
data2 = zeros(m2,n2,p1) ;
for i = 1:p1
data2(:,:,i) = interp2(X1,Y1,data1(:,:,i)',X2,Y2)' ;
end
参考
カテゴリ
Help Center および File Exchange で NetCDF についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!