%% 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.

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','NC_DOUBLE',dimid)

% netcdf.defVar returns a numeric identifier for the new variable.
%
% Close the file.

netcdf.close(ncid)

% Copyright 2015 The MathWorks, Inc.