主要内容

createLabel

创建工程标签

说明

labelDefinitions = createLabel(category,LabelNames) 在指定类别中创建新标签。如果您之前使用 findCategory 函数获取了 Category 对象,请使用此语法。

示例

示例

全部折叠

打开 Times Table App 工程。使用 currentProject 从当前加载的工程创建一个工程对象。

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

获取第一个现有类别。

cat = proj.Categories(1)
cat = 

  Category with properties:

                Name: "Classification"
        SingleValued: 1
            DataType: "none"
    LabelDefinitions: [1×7 matlab.project.LabelDefinition]

在类别中定义一个新标签。

createLabel(cat,"Future");

打开 Times Table App 工程。使用 currentProject 从当前加载的工程创建一个工程对象。

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

创建一个名为 "Engineers" 的新标签类别,用于表示工程中的文件所有权。这些标签具有用于附加字符向量数据的 char 数据类型。

createCategory(proj,"Engineers","char");

使用 findCategory 函数按名称获取新类别

engineersCategory = findCategory(proj,"Engineers");

在新类别中创建标签。

createLabel(engineersCategory,["Tom","Harry"]);

将新标签之一附加到工程中的文件。

label = addLabel(myfile,"Engineers","Tom");

获取该标签并添加数据。

label.Data = "Maintenance responsibility"
  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'char'
            Data: "Maintenance responsibility"
            Name: "Tom"
    CategoryName: "Engineers"

输入参数

全部折叠

新标签的类别,指定为 Category 对象。通过访问 Categories 属性(使用类似 proj.Categories(1) 的语法)获取 Category 对象,或使用 findCategory 函数。要创建一个新类别,请使用 createCategory 函数。

新标签的名称,指定为字符串数组或字符向量元胞数组。

输出参量

全部折叠

标签定义,以 labelDefinition 对象数组形式返回。

提示

  • 要通过一步在现有类别中创建和附加新标签,请改用 addLabel

  • 要创建一个新标签类别,请先使用 createCategory

版本历史记录

在 R2019a 中推出

全部展开