主要内容

findLabel

Get project file label

Description

example

label= FindLabel(file,分类名称,labelName)从指定的文件中获取指定类别中指定的标签。它返回标签定义及其附加数据。当您知道标签名称和类别时,请使用此语法。如果找不到标签,findLabelreturns an empty array.

example

label= FindLabel(file,labelDefinition)gets the label defined by the specified label definition object. Use this syntax if you previously got alabelDefinitionby accessing aLabelsproperty, for instance by using an expression likemyfile.Labels(1).

example

label= FindLabel(类别,labelName)gets a label using a category object rather than a file name and category name. Use this syntax if you have a category object gotten from theproj.Categories属性或使用findCategoryfunction.

Examples

collapse all

Find all project files with the label "Utility"

打开时代表应用程序项目。利用当前的项目to create a project object from the currently loaded project.

matlab.project.example.timesTable proj = currentProject;

Get the list of project files.

files = proj.Files;

Loop through the files. Get each file's extension by taking the last element returned by thefilepartsfunction. If the file has the extension.m, attach the label "Utility".

forfileIndex = 1:numel(file)file = file(fileIndex);[〜,〜,fileextension] = fileparts(file.path);ifstrcmp(fileExtension,".m") addLabel(file,"Classification",“效用”);endend

利用thefindLabelfunction to find all the files with the label "Utility" and add them to the arrayutilityFilesToReview.

utilityFilesToReview = {};forjj=1:numel(files) thisFile = files(jj); label = findLabel(thisFile,"Classification",“效用”);if(~isempty(label))%这是一个标有“实用程序”的文件。添加到公用事业文件列表。UtilityFilestReOveiew = [utilityFileStoreView;这个文件];endend

打开时代表应用程序项目。利用当前的项目to create a project object from the currently loaded project.

matlab.project.example.timesTable proj = currentProject;

Get a file by name.

myfile = findFile(proj,“源/timestablegame.m”);

通过名称从该文件中获取标签。

label = findLabel(myfile,"Classification","Design");
label = Label with properties: File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m" DataType: 'none' Data: [] Name: "Design" CategoryName: "Classification"

检查Labelsproperty of the file to get an array ofLabelobjects, one for each label attached to the file. Index into theLabelsproperty to get the label definition attached to the particular file.

labels = myfile.Labels labeldefinition = myfile.Labels(1)

从标签定义中获取标签。

label = findLabel(myfile,labeldefinition);

打开时代表应用程序项目。利用当前的项目to create a project object from the currently loaded project.

matlab.project.example.timesTable proj = currentProject;

Get a category.

类别= proj.Categories(1)
类别= Category with properties: Name: "Classification" SingleValued: 1 DataType: "none" LabelDefinitions: [1×7 matlab.project.LabelDefinition]

Get a label definition from that category.

ld = findLabel(category,"Design")
ld = LabelDefinition with properties: Name: "Design" CategoryName: "Classification"

Input Arguments

collapse all

File to search in, specified as aProjectFileobject or an array of file objects. You can get the file object by examining the project’s Files property (using the syntaxproj.files), or useFindfileto get a file by name. The file must be in the specified project.

Name of category for the label, specified as a character vector or string scalar.

Name of label, specified as a character vector or string scalar.

标签定义,指定为LabelDefinitionobject gotten from thefile.labelproperty.

类别对象。从proj.Categories属性或使用findCategoryfunction.

Output Arguments

collapse all

标签,返回Label目的。

Introduced in R2019a