netcdf.renameVar

Change name of netCDF variable

Syntax

netcdf.renameVar(ncid,varid,newName)

Description

netcdf.renameVar(ncid,varid,newName) renames the variable identified by varid in the netCDF file identified by ncid.newName is a character string specifying the new name.

This function corresponds to the nc_rename_var 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 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')

% Put file in define mode.
netcdf.redef(ncid)

% Get name of first variable
[varname, xtype, varDimIDs, varAtts] = netcdf.inqVar(ncid,0);

varname

varname =

avagadros_number

% Rename the variable, using a capital letter to start the name.
netcdf.renameVar(ncid,0,'Avagadros_number')

% Verify that the name of the variable changed.
[varname, xtype, varDimIDs, varAtts] = netcdf.inqVar(ncid,0);

varname

varname =

Avagadros_number
Was this topic helpful?