Main Content


Create netCDF dimension


dimid = netcdf.defDim(ncid,dimname,dimlen)


dimid = netcdf.defDim(ncid,dimname,dimlen) creates a new dimension in the netCDF file specified by ncid, where dimname is a character vector or string scalar that specifies the name of the dimension and dimlen is a numeric value that specifies its length. To define an unlimited dimension, specify the predefined constant 'NC_UNLIMITED' for dimlen, using netcdf.getConstant to retrieve the value.

netcdf.defDim returns dimid, a numeric ID corresponding to the new dimension.

This function corresponds to the nc_def_dim function in the netCDF library C API. To use this function, you should be familiar with the netCDF programming paradigm.


Create a new file and define two dimensions in the file. One dimension is an unlimited dimension. To run this example, you must have write permission in your current folder.

% Create a netCDF file.
ncid = netcdf.create('','NC_NOCLOBBER')

% Define a dimension.
lat_dimID = netcdf.defDim(ncid,'latitude',360);

% Define an unlimited dimension.
long_dimID = netcdf.defDim(ncid,'longitude',...