createCategory
创建工程标签的类别
语法
说明
createCategory(
在指定工程中创建一个新标签类别。proj
,categoryName
)
createCategory(
还指定要存储在新类别标签中的数据的类型。有关数据类型的详细信息,请参阅MATLAB 基础类。proj
,categoryName
,dataType
)
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
输入参数
proj
— 工程
matlab.project.Project
对象
工程,指定为 matlab.project.Project
对象。使用 currentProject
从当前加载的工程创建一个工程对象。
categoryName
— 类别的名称
字符向量 | 字符串标量
要创建的标签类别的名称,指定为字符向量或字符串标量。
dataType
— 要存储在标签中的数据的类型
字符向量 | 字符串标量
要存储在新类别的标签中的数据类型,指定为字符向量或字符串标量。
提示
创建一个新类别后,您可以使用 createLabel
函数在该新类别中创建标签。
版本历史记录
在 R2019a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)