Skip to Main Content Skip to Search
Product Documentation

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

See Also

netCDF.defVar | netCDF.inqVar | netCDF.putVar

  


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