How to extract the data from .nc file based on longitude and latitude,time?
显示 更早的评论
Hi, I have to extract the data from netcdf file based on lat,long and time. I have written the following code.
ncid = netcdf.open('\C:\Users\divecha21\Desktop\errorBar\tasmax_day_BNU-ESM_rcp85_r1i1p1_20060101-21001231.nc','NC_NOWRITE');
peaksData = ncinfo('\C:\Users\divecha21\Desktop\errorBar\tasmax_day_BNU-ESM_rcp85_r1i1p1_20060101-21001231.nc','tasmax');
ncdisp('\C:\Users\divecha21\Desktop\errorBar\tasmax_day_BNU-ESM_rcp85_r1i1p1_20060101-21001231.nc','tasmax');
[ndim, nvar, natt, unlim] = netcdf.inq(ncid)
[dimname, dimlength] = netcdf.inqDim(ncid, 0)
[dimname, dimlength] = netcdf.inqDim(ncid, 1)
[dimname, dimlength] = netcdf.inqDim(ncid, 2)
lon = netcdf.getVar(ncid,0,0,128)
%time = netcdf.getVar(ncid,2,0,34675)
lat = netcdf.getVar(ncid,1,0,64)
latlim = [5.25 36.75];
lonlim = [60.25 97.25];
precJanuary = netcdf.getVar(ncid,2,[60.25 5.25 1],[97.25 36.75 1]);
Actually I have global temperature data i have to extract only india. After execution,I got the following error.
>> sample1
Error using ncread Expected start to be integer-valued.
Error in internal.matlab.imagesci.nc/read (line 557) validateattributes(start,{'numeric'},...
Error in ncread (line 58) vardata = ncObj.read(varName, varargin{:});
Error in sample1 (line 27) precJanuary = ncread('\C:\Users\divecha21\Desktop\errorBar\tasmax_day_GFDL-ESM2M_rcp85_r1i1p1_20060101-20101231.nc','tasmax',[60.25 5.25 1],[97.25 36.75 1]);
Can any one help me to clear this? I am new to matlab.
Thank you
5 个评论
dpb
2014-5-17
Format your code to be legible. Add two blanks in front of first line and reintroduce line breaks where they belong. Keep at it until looks right in preview window. Don't put extra blank lines in; if do need one, reinsert the leading double-blanks to get back to code formatting (yes, I know, it's a pita; but TMW in their infinite wisdom uses a textbox w/ default word-wrap 'on' for a code forum... :( )
alagu mathi
2014-5-18
Ashish Uthama
2014-5-19
Did you try using NCREAD itself? (NCINFO will give you dimension info about a variable).
alagu mathi
2014-5-20
Mohnish sinha
2014-11-10
will you please write the revised code for extracting nc files, I am looking for the data for India...
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 NetCDF Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!