How to extract the data from .nc file based on lat,lon ?

1 回表示 (過去 30 日間)
alagu mathi
alagu mathi 2014 年 5 月 26 日
コメント済み: alagu mathi 2014 年 8 月 11 日
Hi, I have .nc file. I have to extract the data based on lat,lon points. I tried the following code,
precJanuary = ncread('\C:\Users\divecha21\Desktop\errorBar\tasmax_day_GFDL- ESM2M_rcp85_r1i1p1_20060101-20101231.nc','tasmax',[1 1 1],[10 10 1]);
disp(precJanuary);
After the execution I got the data for 10 lat,lon points.
Instead of that start,end I tried latitude,longitude limits.
I got the following error,
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]);
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 28) 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?
Thank you

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 5 月 26 日
According to the ncread command documentation (type help ncread in the Command Window) the START and COUNT inputs are defined as:
For an N-dimensional variable START is a vector of 1-based indices of length N
specifying the starting location. COUNT is also a vector of length N specifying
the number of elements to read along corresponding dimensions. If a particular
element of COUNT is Inf, data is read until the end of that dimension.
In the above code, you are supplying rational (non-integer) inputs as the START and COUNT, hence the error Expected start to be integer-valued.
  2 件のコメント
alagu mathi
alagu mathi 2014 年 5 月 27 日
編集済み: alagu mathi 2014 年 5 月 27 日
Thank you Geoff Hayes. Your answer is correct. But I wants to extract the data only indian region, Actually I have global data. So instead of start and count i tried india lat, lon limits ([60.25 5.25 1],[97.25 36.75 1]). I got the following error,
Error using ncread Expected start to be integer-valued.
Could you please help me to clear this problem?
Geoff Hayes
Geoff Hayes 2014 年 5 月 27 日
編集済み: Geoff Hayes 2014 年 5 月 27 日
The ncread command is expecting integer inputs for START and COUNT not rational inputs like 60.25, 5.25, etc. Those are not valid inputs and so you observe the above error.
You may have to read through all of the data until you find the region that corresponds to India. Unless there is another variable that may hint at which records belong to the area of interest?

サインインしてコメントする。

その他の回答 (1 件)

Catubela matlab
Catubela matlab 2014 年 8 月 8 日
@alagu mathi did you find a way to do this? I'm also interested in how to extract data for a subdomain based on lat lon values
  1 件のコメント
alagu mathi
alagu mathi 2014 年 8 月 11 日
I used geoshow(lat,lon) command to extract the data for subregion. You can try this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by