Main Content

cdflib.renameVar

更改变量名称

语法

cdflib.renameVar(cdfId,varNum,newName)

说明

cdflib.renameVar(cdfId,varNum,newName) 对常用数据格式 (CDF) 文件中的变量进行重命名。

cdfId 标识 CDF 文件。varNum 是标识变量的数值。变量编号从 0 开始。newName 是指定要赋给变量的名称的字符向量或字符串标量。

示例

创建一个 CDF 文件,并在该 CDF 文件中创建一个变量,然后对该变量进行重命名。要运行此示例,当前必须位于可写文件夹中。

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

参考

此函数对应于 CDF 库的 C API 例程 CDFrenamezVar

要使用此函数,必须熟悉 CDF C 接口。您可以在 CDF 网站上访问 CDF 文档。