Main Content

createLabel

创建工程标签

说明

示例

createLabel(category,newLabelName) 在指定类别中创建一个新标签。如果您以前通过访问 Categories 属性获得 Category 对象(例如使用 proj.Categories(1) 之类的语法),请使用以上语法。

示例

全部折叠

打开 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");
createLabel(engineersCategory,"Harry");

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

myfile = findFile(proj,"source/timesTableGame.m");
addLabel(myfile,"Engineers","Tom");

获取该标签并添加数据。

label = findLabel(myfile,"Engineers","Tom");
label.Data = "Maintenance responsibility";
disp(label)
  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 函数。

新标签的名称,指定为字符向量。

提示

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

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

版本历史记录

在 R2019a 中推出