Main Content

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 vector or string scalar 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.

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