findLabel - Get project file label - MATLAB (original) (raw)
Syntax
Description
[label](#mw%5F686a0338-8ad6-410a-a606-61ef67a287ae) = findLabel([files](#mw%5F8d5a1083-8f9b-4954-9501-a480687eb99a),[categoryName](#mw%5Fcf133601-a2ec-4c1a-a122-1f698b353f56),[labelName](#mw%5F908eb3b1-d37f-4e08-a7aa-4e4367f85452))
gets the specified label, in the specified category, from the specified files. The function returns the label object and the attached data. Use this syntax when you know the label name and category. If the label is not found,findLabel
returns an empty array.
[label](#mw%5F686a0338-8ad6-410a-a606-61ef67a287ae) = findLabel([files](#mw%5F8d5a1083-8f9b-4954-9501-a480687eb99a),[labelDefinition](#mw%5Fb50becdb-2626-46b8-8095-a5d22f8bb601))
gets the label defined by the specified label definition object. Use this syntax if you previously created a labelDefinition
using aLabels
property, for instance by using an expression likecategory.LabelDefintions(1)
.
[labelDefintion](#mw%5Fbb35d731-d9b4-437b-9a9d-bd99c8c19489) = findLabel([category](#mw%5F40cd185a-919d-4f68-89ac-0782265546b1),[labels](#mw%5Ff9293a80-b2cb-45cf-8e86-21acb6912b7b))
gets the label definition that you can use to find files with the label. Use this syntax if you created a category object using thecreateCategory
or the findCategory
functions.
Examples
Find all project files with the label "Design
".
Open the Times Table App project. Use currentProject
to create a project object from the currently loaded project.
openExample("matlab/TimesTableProjectExample") proj = currentProject;
Get the list of project files.
Use the findLabel
function to find all the files with the label "Design
".
designFilesToReview = [findLabel(files,"Classification","Design").File]'
designFilesToReview =
5×1 string array
"C:\Workspace\TimesTableApp\source\timesTableGame.m"
"C:\Workspace\TimesTableApp\source\timestable.mlapp"
"C:\Workspace\TimesTableApp\utilities\editTimesTable.m"
"C:\Workspace\TimesTableApp\utilities\openRequirementsDocument.m"
"C:\Workspace\TimesTableApp\utilities\runTheseTests.m"
Open the Times Table App project. Use currentProject
to create a project object from the currently loaded project.
openExample("matlab/TimesTableProjectExample") proj = currentProject;
Get a category.
category = proj.Categories(1)
category =
Category with properties:
SingleValued: 1
DataType: "none"
Name: "Classification"
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
Files to search in, specified as an array of ProjectFile
objects. You can create a project file object by examining the project files property using the syntax proj.Files
, or by usingfindFiles.
Name of category for the label, specified as a string scalar or a character vector.
Label name, specified as a string scalar or a character vector.
Label names, specified as a string array or a cell array of character vectors.
Label definition, specified as a LabelDefinition
object gotten from category.LabelDefintions(1)
.
Category object. Create a category object from theproj.Categories
property or by using the findCategory function.
Output Arguments
Label, returned as an array of Label
objects.
Label definition, returned as an array ofLabelDefinition
objects.
Version History
Introduced in R2019a
Starting in R2025a, you can get label definitions for multiple labels in a category simultaneously.
proj = currentProject; category = proj.Categories(1); findLabel(category,["Design","utilities"])