Main Content

netcdf.renameAtt

Change name of netCDF attribute

Syntax

netcdf.renameAtt(ncid,varid,oldName,newName)

Description

netcdf.renameAtt(ncid,varid,oldName,newName) changes the name of the attribute specified in oldName to the name specified in newName.

Specify oldName and newName as character vectors or string scalars.

ncid is a netCDF file identifier returned by netcdf.create or netcdf.open.

varid identifies the variable to which the attribute is associated. To specify a global attribute, use netcdf.getConstant('NC_GLOBAL') for varid.

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

Examples

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

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

% Get the ID of a variable the attribute is associated with.
varID = netcdf.inqVarID(ncid,'avagadros_number')

% Rename the attribute.
netcdf.renameAtt(ncid,varID,'description','Description');

% Verify that the name changed.
attname = netcdf.inqAttName(ncid,varID,0)

attname =

Description