필터 지우기
필터 지우기

How to extract the data from .nc file based on longitude and latitude,time?

조회 수: 17 (최근 30일)
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
alagu mathi
alagu mathi 2014년 5월 20일
Yes,I tried ncinfo() but still i could n't clear that problem.
Mohnish sinha
Mohnish sinha 2014년 11월 10일
will you please write the revised code for extracting nc files, I am looking for the data for India...

댓글을 달려면 로그인하십시오.

채택된 답변

Ashish Uthama
Ashish Uthama 2014년 5월 20일
편집: Ashish Uthama 2014년 5월 20일
The nc* functions and the netcdf.* functions represent two independent ways to access a NetCDF file. I would recommend sticking to nc* functions until you get comfortable enough to directly access the NetCDF library interface using the netcdf.* functions (it uses C style indexing and dimension ordering which is different from what nc* functions report and use).
Instead of
precJanuary = netcdf.getVar(ncid,2,[0 0 0],[128 64 1]);
try
precJanuary = ncread(filename, varname,[1 1 1],[128 64 1]);
  댓글 수: 3
Jonas Damsbo
Jonas Damsbo 2018년 12월 27일
I try to use your code line:
z = ncread(ncfiles(i).name,'z',[1 1 1],[360 181 1]);
But I got the error:
Index exceeds array bounds. Why?
Lee Key
Lee Key 2021년 6월 2일
편집: Lee Key 2021년 6월 2일
What does these elements (1 1 1 etc.. ) represents in this [1 1 1],[360 181 1]?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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