Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

createCategory

创建工程标签的类别

说明

示例

createCategory(proj,categoryName) 在指定工程中创建一个新标签类别。

示例

createCategory(proj,categoryName,dataType) 还指定要存储在新类别标签中的数据的类型。有关数据类型的详细信息,请参阅MATLAB 基础类

示例

createCategory(proj,categoryName,dataType,"single-valued") 指定单值类别,您只能将该类别中的一个标签附加到一个文件。如果不指定单值类别,则可以将类别中的多个标签附加到一个文件。

示例

newcategory = createCategory(___) 将新类别返回为 Category 对象。将该语法用于之前的任何输入参数组合。

示例

全部折叠

创建新标签类别来指示文件的所有者,并将新标签以及标签数据附加到文件。

打开 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: [1x80 char]
            Data: "Maintenance responsibility"
        DataType: 'char'
            Name: "Tom"
    CategoryName: "Engineers"

使用 double 数据类型创建标签的类别,用于数值数据。

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

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

创建一个新的标签类别。将数据类型指定为“double”。这是 MATLAB® 用于数字的默认数据类型。

coverageCategory = createCategory(proj,"Coverage","double")
category = 

  Category with properties:

                Name: "Coverage"
            DataType: 'double'
    LabelDefinitions: []

在新类别中创建一个标签,并将其添加到工程中的文件中。

createLabel(coverageCategory,"Test");
myfile = findFile(proj,"source/timesTableGame.m");
label = addLabel(myfile,"Coverage","Test");

向该标签中添加数值数据。

label.Data = 80
newLabel = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'double'
            Data: 80
            Name: "Test"
    CategoryName: "Coverage"

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

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

创建一个标签类别以指示文件所有权,并指定单值以限制对每个文件只能附加该类别中的一个标签。

engineersCategory = createCategory(proj,"Engineers","char", "single-valued");

在新类别中创建一个标签,并将其添加到工程中的文件中。

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

  Label with properties:

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

在新类别中创建第二个标签,并将其添加到工程中的同一文件。MATLAB 会用新标签替换第一个标签。

createLabel(engineersCategory,"Harry");
addLabel(myfile,"Engineers","Harry")
ans = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'char'
            Data: []
            Name: "Harry"
    CategoryName: "Engineers"

检查第一个标签是否仍然附加到该文件。

findLabel(myfile,"Engineers","Tom")
ans = 

  0×0 Label array with properties:

    File
    DataType
    Data
    Name
    CategoryName

输入参数

全部折叠

工程,指定为 matlab.project.Project 对象。使用 currentProject 从当前加载的工程创建一个工程对象。

要创建的标签类别的名称,指定为字符向量或字符串标量。

要存储在新类别的标签中的数据类型,指定为字符向量或字符串标量。

提示

创建一个新类别后,您可以使用 createLabel 函数在该新类别中创建标签。

版本历史记录

在 R2019a 中推出