Skip to Main Content Skip to Search
Product Documentation

netcdf.reDef - Put open netCDF file into define mode

Syntax

netcdf.reDef(ncid)

Description

netcdf.reDef(ncid) puts an open netCDF file into define mode so that dimensions, variables, and attributes can be added or renamed. Attributes can also be deleted in define mode. ncid is a valid NetCDF file ID, returned from a previous call to netcdf.open or netcdf.create.

This function corresponds to the nc_redef function in the netCDF library C API. To use this function, you should be familiar with the netCDF programming paradigm. See netcdf for more information.

Examples

This example opens a local copy of the example netCDF file included with MATLAB, example.nc.

% Open a netCDF file.
ncid = netcdf.open('my_example.nc','NC_WRITE')

% Try to define a dimension. 
dimid = netcdf.defdim(ncid, 'lat', 50); % should fail.
??? Error using ==> netcdflib
NetCDF: Operation not allowed in data mode

Error in ==> defDim at 22
dimid = netcdflib('def_dim', ncid,dimname,dimlen);
 
% Put file in define mode.
netcdf.reDef(ncid);

% Try to define a dimension again. Should succeed.
dimid = netcdf.defDim(ncid, 'lat', 50);

See Also

netcdf.create | netcdf.endDef | netcdf.open

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS