Reading 3-dimensional netcdf data
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I downloaded precipitation data from SIM2RAIN. It is 3 dimensional and temporal resolution is 1 day. For example for year 2005, my file size is 365(days)*1440(long)*720(lat). I want to show precipitation data for each day in matrix (1440,720). So, It means ı will have 365 files. My file name is CCI_SM2RAIN_2005_BC.nc. I can do it by using Arcmap but it is very time consuming. How can I do this in matlab ? Thanks for help.
採用された回答
You can read your nc file like shown below....Change the variables in the below to your variables naming converntion in your file.
ncfile='CCI_SM2RAIN_2005_BC.nc'
lon = ncread(ncfile,'Longitude') ; nx = length(lon) ;
lat = ncread(ncfile,'Latitude') ; ny = length(lat) ;
time = ncread(ncfile,'Time') ;
for i = 1:length(time)
z = ncread(ncfile,'Rainfall',[i 1 1 ],[1, nx ny]) ;
z = squeeze(z) ;
pcolor(lon,lat,z') ;
title(sprintf("Time step = %d",i)) ;
shading interp
drawnow
end
9 件のコメント
Gokhan Kayan
2020 年 6 月 18 日
Thanks for the comment KSSV. But the file does not accept longitude latitude and time as variables. It gives error when ı try to run it. My only variable is rainfall here.
KSSV
2020 年 6 月 18 日
I already mentioned that you have to change the variable names as according to your file variable names.
Gokhan Kayan
2020 年 6 月 18 日
I run it again by changing variable names. My new code is like this:
ncfile='CCI_SM2RAIN_2005_BC.nc'
lon = ncread(ncfile,'Longitude') ; nx = length(lon) ;
lat = ncread(ncfile,'Latitude') ; ny = length(lat) ;
time = ncread(ncfile,'Time') ;
for i = 1:length(time)
z = ncread(ncfile,'z',[1 1 i],[nx ny 1]) ;
pcolor(lon,lat,z') ;
shading interp
drawnow
end
And it gives me this errors.
Error using internal.matlab.imagesci.nc/getGroupAndVarid (line 2096)
Could not find variable or group 'z' in file.
Error in internal.matlab.imagesci.nc/read (line 593)
[gid, varid] = getGroupAndVarid(this, location);
Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});
Error in nc (line 6)
z = ncread(ncfile,'z',[1 1 i],[nx ny 1]) ;
KSSV
2020 年 6 月 18 日
What is 3D variable? You need to change it from 'z' to what it is in the file.
Gokhan Kayan
2020 年 6 月 18 日
My 3D variable is 'Rainfall'. I think we should arrange this
z = ncread(ncfile,'Rainfall',[1 1 i],[nx ny 1]) ;
as
z = ncread(ncfile,'Rainfall',[i 1 1],[ 1 nx ny]) ;
because Time is first place for rainfall. 2nd one is longitude and 3rd variable is latitude.
Then I run code
ncfile='CCI_SM2RAIN_2005_BC.nc'
lon = ncread(ncfile,'Longitude') ; nx = length(lon) ;
lat = ncread(ncfile,'Latitude') ; ny = length(lat) ;
time = ncread(ncfile,'Time') ;
for i = 1:length(time)
z = ncread(ncfile,'Rainfall',[i 1 1],[ 1 nx ny]) ;
pcolor(lon,lat,'Rainfall') ;
shading interp
drawnow
end
Now it gives me this error
Error using pcolor (line 58)
Color data input must be a matrix.
Error in nc (line 7)
pcolor(lon,lat,'Rainfall') ;
KSSV
2020 年 6 月 18 日
ncfile='CCI_SM2RAIN_2005_BC.nc'
lon = ncread(ncfile,'Longitude') ; nx = length(lon) ;
lat = ncread(ncfile,'Latitude') ; ny = length(lat) ;
time = ncread(ncfile,'Time') ;
for i = 1:length(time)
z = ncread(ncfile,'Rainfall',[i 1 1],[ 1 nx ny]) ;
pcolor(lon,lat,z') ;
shading interp
drawnow
end
KSSV
2020 年 6 月 18 日
Edited the answer.
Also you can read the entire data into MATLAB workspace using:
z = ncread(ncfile.'Rainfall') ;
for i = 1:length(time)
R = squeeze(z(i,:,:)) ;
pcolor(lon,lat,R')
shading interp
drawnow
end
I have edited the original answer again.....now it will work..check it.
Gokhan Kayan
2020 年 6 月 18 日
Thanks. You are great, It worked perfectly :)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で NetCDF についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
