addLabel
将标签附加到工程文件
说明
addLabel(
将指定类别中的指定标签附加到指定文件。file
,categoryName
,labelName
)
addLabel(
附加具有指定的文本或数值数据的标签。您无法将标签数据添加到内置标签,因为它们为只读。file
,categoryName
,labelName
,labelData
)
示例
将标签附加到工程文件
打开 Times Table App 工程。使用 currentProject
从当前加载的工程创建一个工程对象。
openExample("matlab/TimesTableProjectExample")
proj = currentProject;
按名称获取一个文件。
myfile = findFile(proj,"source/timesTableGame.m")
myfile = ProjectFile with properties: Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" Labels: [1×1 matlab.project.Label] Revision: "286043ae7ee557100902fb645a6c97eca5d50472" SourceControlStatus: Unmodified
通过获取文件的 Labels
属性查看现有标签。
myfile.Labels
ans = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Design" CategoryName: "Classification"
将标签 "Artifact"
附加到 "Classification"
类别的文件上。
addLabel(myfile,"Classification","Artifact")
ans = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Artifact" CategoryName: "Classification"
现在有两个标签,即原始标签和添加的标签。要仅查看添加的标签,请对 Labels
属性进行索引。
reviewlabel = myfile.Labels(1)
reviewlabel = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Artifact" CategoryName: "Classification"
撤除文件的新标签。文件现在只有一个标签。
removeLabel(myfile,reviewlabel) myfile
myfile = ProjectFile with properties: Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" Labels: [1×0 matlab.project.Label] Revision: "286043ae7ee557100902fb645a6c97eca5d50472" SourceControlStatus: Unmodified
将标签附加到文件子集
将 "Classification"
类别中的标签 "Utility"
附加到工程中所有扩展名为 .m
的文件。
打开 Times Table App 工程。使用 currentProject
从当前加载的工程创建一个工程对象。
openExample("matlab/TimesTableProjectExample")
proj = currentProject;
获取文件列表。
files = proj.Files;
遍历每个文件。为仅获取文件扩展名,可使用 fileparts
函数来提取最后一部分。如果文件扩展名为 .m
,则附加标签 "Utility"。
for fileIndex = 1:numel(files) file = files(fileIndex); [~, ~, fileExtension] = fileparts(file.Path); if strcmp(fileExtension,".m") addLabel(file,"Classification","Utility"); end end
在工程的文件视图中,对于 utilities 文件夹中每个 .m
文件,分类列会显示标签 Utility。
将标签和标签数据附加到文件
创建标签类别 "Review"
和标签 "To Review",然后将标签和标签数据附加到一个文件。您无法将标签数据添加到内置标签,因为它们为只读。
打开 Times Table App 工程。使用 currentProject
从当前加载的工程创建一个工程对象。
openExample("matlab/TimesTableProjectExample")
proj = currentProject;
创建一个新类别 "Review"
。
createCategory(proj,"Review","char");
对于该新类别,创建标签 "To Review"
。
reviewCategory = findCategory(proj,"Review"); createLabel(reviewCategory,"To Review");
按名称获取一个文件。
myfile = findFile(proj,"source/timesTableGame.m")
myfile = ProjectFile with properties: Path: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" Labels: [1×1 matlab.project.Label] Revision: "c7603d5dd71a40484974c3f1c45d839819b7b061" SourceControlStatus: Unmodified
将标签 "To Review"
和标签数据字符向量附加到该文件。
addLabel(myfile,"Review","To Review","Whole team design review")
ans = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'char' Data: 'Whole team design review' Name: "To Review" CategoryName: "Review"
在工程的文件视图中,对于 timesTableGame.m
文件,Review 列显示具有标签数据的 To Review 标签。
您也可以使用 Data
属性设置或更改标签数据。
mylabel = myfile.Labels(1);
mylabel.Data = "Final review";
输入参数
file
— 要添加标签的文件
ProjectFile
对象
要添加标签的文件,指定为 ProjectFile
对象。您可以通过检查工程的文件属性 (proj.Files
) 来获取 ProjectFile
对象,或通过使用 findFile
按名称查找文件。文件必须在工程中。
categoryName
— 标签类别的名称
字符向量 | 字符串标量
标签类别的名称,指定为字符向量或字符串标量。
labelName
— 标签的名称
字符向量 | 字符串标量 | LabelDefinition
对象
要附加的标签的名称,指定为字符向量、字符串标量,或指定为 file.Label
属性或 findLabel
函数返回的 LabelDefinition
对象。您可以指定工程中尚不存在的新标签名称。
labelData
— 要附加到标签的数据
字符向量 | 字符串标量 | 数值
要附加到标签的数据,指定为字符向量、字符串标量或数值。数据类型取决于标签定义。使用 file.Label
或 findLabel
获得标签以检查其 DataType
属性。
版本历史记录
在 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)