필터 지우기
필터 지우기

Creating a netcdf File in Matlab 2010b

조회 수: 2 (최근 30일)
Atreyee Bhattacharya
Atreyee Bhattacharya 2011년 5월 31일
답변: Carlos Batista 2014년 10월 29일
Hi, I need to create a netCDF file with three variables (Latitude, longitude and r values) that I have generated from a different Matlab program. Can anyone suggest a method that will work in the the newest version of Matlab (2010b)?
Thank you Atreyee

답변 (3개)

Ashish Uthama
Ashish Uthama 2011년 5월 31일
The example here shows how to create one variable in a NetCDF file. Try to extend that to three and update your question if you have trouble.
R2011a is the current 'newest' version. If you are able to upgrade, you can use the newer nccreate and ncwrite functions.

Dave Correa
Dave Correa 2011년 7월 10일
Hello;
Here an example.
I hope this is of some help.
Regards
Dave Correa
E-mail:correa.dave30@gmail.com
close all, clear all, clc
yearini=1960;
yearfin=1970;
%%--------------------
nt=144;
nx=1440;
ny=720;
lon=linspace(-180,180,nx);
lat=linspace(90,-90,ny);
time=1:nt;
[mlat,mlon]=meshgrid(lat,lon);
disp('Creando file Netcdf...')
filenc=['Data.nc'];
ncid = netcdf.create(filenc,'NC_WRITE');
% Crear dimensiones
dimid_lon = netcdf.defDim(ncid,'longitude',nx);
dimid_lat = netcdf.defDim(ncid,'latitude',ny);
dimid_time = netcdf.defDim(ncid,'time',nt);
% Crear variables y atributos
varid_lon = netcdf.defVar(ncid,'longitude','double',dimid_lon);
netcdf.putAtt(ncid,varid_lon,'long_name','Longitude')
netcdf.putAtt(ncid,varid_lon,'units','degrees_east')
%
varid_lat = netcdf.defVar(ncid,'latitude','double',dimid_lat);
netcdf.putAtt(ncid,varid_lat,'long_name','Latitude')
netcdf.putAtt(ncid,varid_lat,'units','degrees_north')
%
varid_time = netcdf.defVar(ncid,'time','double',dimid_time);
netcdf.putAtt(ncid,varid_time,'long_name','Time')
netcdf.putAtt(ncid,varid_time,'units','Months since 1960-01-01 00:00:00')
%
varid_prec = netcdf.defVar(ncid,'prec','double',[dimid_lon,dimid_lat,dimid_time]);
netcdf.putAtt(ncid,varid_prec,'long_name','Variable')
netcdf.putAtt(ncid,varid_prec,'units','mm')
netcdf.putAtt(ncid,varid_prec,'missing_value',-9999)
netcdf.endDef(ncid)
% % % Agregar datos de coordenadas
netcdf.putVar(ncid,varid_lon,lon);
netcdf.putVar(ncid,varid_lat,lat);
netcdf.putVar(ncid,varid_time,time);
m=1;
for year=yearini:yearfin
for mes=1:12
netcdf.putVar(ncid,varid_prec,[0 0 m-1],[nx ny 1],tmp);
m=m+1;
end
end
netcdf.close(ncid)

Carlos Batista
Carlos Batista 2014년 10월 29일
Anyone know how to declare the variable tmp in David's script !?

카테고리

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