Matlab 基于给定lat和long的一个位置提取netcdf pr
我正在使用MATLAB从netcdf文件中提取特定lat和长坐标的整个时间段的pr变量 我所在的位置lat=36,long=9.15。netcdf文件的纬度矩阵为453 X 453,经度矩阵为453 X 453 变量:Matlab 基于给定lat和long的一个位置提取netcdf pr,matlab,netcdf,coordinate,Matlab,Netcdf,Coordinate,我正在使用MATLAB从netcdf文件中提取特定lat和长坐标的整个时间段的pr变量 我所在的位置lat=36,long=9.15。netcdf文件的纬度矩阵为453 X 453,经度矩阵为453 X 453 变量: lon Size: 453x453 Dimensions: x,y Datatype: double Attributes: standard
lon
Size: 453x453
Dimensions: x,y
Datatype: double
Attributes:
standard_name = 'longitude'
long_name = 'longitude'
units = 'degrees_east'
lat
Size: 453x453
Dimensions: x,y
Datatype: double
Attributes:
standard_name = 'latitude'
long_name = 'latitude'
units = 'degrees_north'
time
Size: 1826x1
Dimensions: time
Datatype: double
Attributes:
standard_name = 'time'
units = 'days since 1949-12-01'
calendar = 'gregorian'
bounds = 'time_bnds'
axis = 'T'
long_name = 'time'
pr
Size: 453x453x1826
Dimensions: x,y,time
Datatype: single
Attributes:
_FillValue = 1.000000020040877e+20
grid_mapping = 'Lambert_Conformal'
standard_name = 'precipitation_flux'
long_name = 'precipitation'
units = 'kg m-2 s-1'
cell_methods = 'time: mean'
coordinates = 'lat lon'
现在。。。我想在netcdf文件的纬度和经度矩阵中找到与我的实际纬度和经度坐标最近的点
我是这样做的:
d = (mylat-Latnetcdf).^2+(mylong-Longnetcdf).^2;
[~, ind] = min(d(:));
resultlat = lat(ind); %// use that index to obtain the result
resultlong = long(ind);
…这将返回ind=50049
…然后,当我尝试使用以下命令从文件中提取pr变量时:
ncread(netcdfname,'pr', [50049,50049, 1], [1 1 inf]);
…它返回错误:
Error using netcdflib
The NetCDF library encountered an error during execution of 'getVarsFloat' function - 'Index exceeds dimension
bound (NC_EINVALCOORDS)'.
Error in netcdf.getVar (line 136)
data = netcdflib(funcstr,ncid,varid,varargin{:});
Error in internal.matlab.imagesci.nc/read (line 635)
data = netcdf.getVar(gid, varid, ...
Error in ncread (line 58)
vardata = ncObj.read(varName, varargin{:});
从bash中的命令行:
cdo remapnn,lon=9.15/lat=36 input.nc output.nc
我不知道matlab,使用python,但需要分别计算lat和long的ind。它们可能有也可能没有不同的索引。您的ncread索引应该类似于[lon\u ind,lat\u ind,1]。我觉得有人不喜欢CDO。。。这些单线答案都被打了分数;-)Laykeh,这对你有帮助吗?我确实否决了你的一些答案(不,我确实喜欢CDO…:-);IMHO针对特定语言提出的问题不应回答为“您可以用另一种语言/使用另一种工具轻松完成”。如果我有一个我想用Python解决的问题,我想看看Python的解决方案,而不是NCO/CDO/NCL/R/Fortran/IDL/Matlab/。。。。(此外,请参见示例)但有时人们不知道是否存在CDO/NCO来完成任务,我看到人们评论说,他们因此转向了基于CDO/NCO的解决方案。通常情况下,任务才是关键,人们只会问基于某种语言的问题,因为这是他们熟悉的,因此他们试图用它来解决该任务。另外,有时其他用户正在寻找解决特定任务的方法,但他们并不拘泥于特定的语言。。。但是我们走了。。。当它点击-3时,我将删除它,以至少获得一个同级压力徽章;-)顺便问一下,你就是我认识的克米巴特吗-在注释中键入代码是一个混乱的过程,因为您无法格式化它。这是一个答案,即使不是每个人都喜欢的答案,我想这就是投票系统最终的目的。好吧,当你看到另一个巴特时,跟他打个招呼…;-)