How to compare lat lon from text file with netcdf file?

1 回表示 (過去 30 日間)
IMC
IMC 2022 年 2 月 28 日
コメント済み: KSSV 2022 年 2 月 28 日
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

回答 (1 件)

KSSV
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 件のコメント
IMC
IMC 2022 年 2 月 28 日
I didn't get your point. What is meant by 'Each data'?
KSSV
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 ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by