Main Content

findLabel

Get project file label

Since R2019a

Description

example

label= findLabel(file,categoryName,labelName)指定的标签,在指定的category, from the specified file. It returns the label definition and its attached data. Use this syntax when you know the label name and category. If the label is not found,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(category,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.Categoriesproperty or by using thefindCategoryfunction.

Examples

collapse all

Find all project files with the label "Utility"

Open the Times Table App project. UsecurrentProjectto 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(files) file = files(fileIndex); [~,~,fileExtension] = fileparts(file.Path);ifstrcmp(fileExtension,".m") addLabel(file,"Classification",“效用”);endend

Use 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))% This is a file labeled "Utility". Add to the% list of utility files.utilityFilesToReview = [utilityFilesToReview; thisFile];endend

Open the Times Table App project. UsecurrentProjectto create a project object from the currently loaded project.

matlab.project.example.timesTable proj = currentProject;

Get a file by name.

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

Get a label from that file by name.

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

Examine theLabelsproperty 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)

Get a label from the label definition.

label = findLabel(myfile,labeldefinition);

Open the Times Table App project. UsecurrentProjectto create a project object from the currently loaded project.

matlab.project.example.timesTable proj = currentProject;

Get a category.

category = proj.Categories(1)
category = 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.

Label definition, specified as aLabelDefinitionobject gotten from thefile.Labelproperty.

Category object. Get a category object from theproj.Categoriesproperty or by using thefindCategoryfunction.

Output Arguments

collapse all

Label, returned as aLabelobject.

版本;n History

Introduced in R2019a