Main Content

cdflib.renameVar

Change name of variable

Syntax

cdflib.renameVar(cdfId,varNum,newName)

Description

cdflib.renameVar(cdfId,varNum,newName) renames a variable in a Common Data Format (CDF) file.

cdfId identifies the CDF file. varNum is a numeric value that identifies the variable. Variable numbers are zero-based. newName is a character vector or string scalar that specifies the name you want to assign to the variable.

Examples

Create a CDF, create a variable in the CDF, and then rename the variable. To run this example, you must be in a writable folder.

cdfId = cdflib.create("your_file.cdf");

% Create a variable in the file
varNum = cdflib.createVar(cdfId,"Time","cdf_int1",1,[],true,[]);

% Get the name of the variable
name = cdflib.getVarName(cdfId,varNum)
name =

    'Time'
% Rename the variable
cdflib.renameVar(cdfId,varNum,"newName")

% Check the new name
name = cdflib.getVarName(cdfId,varNum)
name =

    'newName'
%Clean up
cdflib.delete(cdfId)
clear cdfId

Tips

  • This function corresponds to the CDF library C API routine CDFrenamezVar.

  • To use this function, you must be familiar with the CDF C interface. You can access the CDF documentation at the CDF website.