www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DefineDimensionAndVariableInNetCDFFileExample.m

    %% Define Dimension and Variable in NetCDF File
% Create a new NetCDF file, define a dimension in the file, and then
% define a variable on that dimension. In NetCDF files, you must create a
% dimension before you can create a variable. To run this example, you
% must have write permission in your current folder.
%%
% Create a new NetCDF file named |foo.nc|.

% Copyright 2015 The MathWorks, Inc.

ncid = netcdf.create('foo.nc','NC_NOCLOBBER');
%%
% Define a dimension in the new file.
dimid = netcdf.defDim(ncid,'x',50);
%%
% Define a variable in the new file using |netcdf.defVar|.
varid = netcdf.defVar(ncid,'myvar','double',dimid)
%%
% |netcdf.defVar| returns a numeric identifier for the new variable.
%%
% Close the file.
netcdf.close(ncid)