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 CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by