addLabel - Attach label to project file - MATLAB (original) (raw)
Attach label to project file
Syntax
Description
addLabel([proj](#mw%5F5f039cbb-150d-44f7-8a99-a48b49b65022),[projectFiles](#mw%5F82f9cc7b-043a-4b7b-9b2e-a9a653615202),[categoryName](#mw%5Fdf539349-bf5f-461c-a8b5-3396b23cba0e),[labelName](#mw%5F75f185cf-95a7-48a6-8268-10ed84e39ae8))
attaches the specified label in the specified category to the filesprojectFiles
in the projectproj
.
addLabel([proj](#mw%5F5f039cbb-150d-44f7-8a99-a48b49b65022),[projectFiles](#mw%5F82f9cc7b-043a-4b7b-9b2e-a9a653615202),[labelName](#mw%5F75f185cf-95a7-48a6-8268-10ed84e39ae8))
attaches the specified label to the files projectFiles
in the project proj
. Use this syntax only if the label name is unique in the project.
addLabel([proj](#mw%5F5f039cbb-150d-44f7-8a99-a48b49b65022),[projectFiles](#mw%5F82f9cc7b-043a-4b7b-9b2e-a9a653615202),[categoryName](#mw%5Fdf539349-bf5f-461c-a8b5-3396b23cba0e),[labelName](#mw%5F75f185cf-95a7-48a6-8268-10ed84e39ae8),[labelData](#mw%5Fdb409694-79e2-45e3-a872-9e6293642056))
attaches the label with the specified text or numeric data to the filesprojectFiles
. You cannot add label data to built-in labels.
addLabel([fileObject](#mw%5F120d38d0-f82a-44ea-94df-712209154fdc),[categoryName](#mw%5Fdf539349-bf5f-461c-a8b5-3396b23cba0e),[labelName](#mw%5F75f185cf-95a7-48a6-8268-10ed84e39ae8))
attaches the specified label in the specified category to the specified file.
addLabel([fileObject](#mw%5F120d38d0-f82a-44ea-94df-712209154fdc),[categoryName](#mw%5Fdf539349-bf5f-461c-a8b5-3396b23cba0e),[labelName](#mw%5F75f185cf-95a7-48a6-8268-10ed84e39ae8),[labelData](#mw%5Fdb409694-79e2-45e3-a872-9e6293642056))
attaches the label with the specified text or numeric data. You cannot add label data to built-in labels as they are read-only.
Examples
Attach a Label to a Project File
Open the Times Table App project. Use currentProject
to create a project object from the currently loaded project.
openExample("matlab/TimesTableProjectExample") proj = currentProject;
Query the existing labels for a file.
filename = fullfile("source","timesTableGame.m"); myfile = findFiles(proj,filename,OutputFormat="ProjectFile"); existingLabel = myfile.Labels
existingLabel =
Label with properties:
File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
DataType: 'none'
Data: []
Name: "Design"
CategoryName: "Classification"
Attach the label "Artifact"
to the file in the category"Classification"
.
newLabel = addLabel(proj,myfile,"Classification","Artifact")
newLabel =
Label with properties:
File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
DataType: 'none'
Data: []
Name: "Artifact"
CategoryName: "Classification"
Examine the label attached to myfile
. The label changed from "Design"
to "Artifact"
.
reviewLabel = myfile.Labels(1)
reviewLabel =
Label with properties:
File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
DataType: 'none'
Data: []
Name: "Artifact"
CategoryName: "Classification"
Detach the new label from the file. The file now has no labels.
removeLabel(proj,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
Attach a Label to a Subset of Files
Attach the label "Utility"
in the"Classification"
category to all files in the project that have the .m
file extension.
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 files.
Attach the label "R2024b"
to all files in the project.
addLabel(proj,files,"Classification","R2024b");
In the project Files view, theClassification column displays the labelR2024b
for every file in the project.
Attach a Label and Label Data to a File
Create the label category "Review"
and the label "To Review", and then attach the label and label data to a file. You cannot add label data to built-in labels as they are read-only.
Open the Times Table App project. Use currentProject
to create a project object from the currently loaded project.
openExample("matlab/TimesTableProjectExample") proj = currentProject;
Create a new category"Review"
.
createCategory(proj,"Review","char");
For the new category, create a label "To Review"
.
reviewCategory = findCategory(proj,"Review"); createLabel(reviewCategory,"To Review");
Attach the label "To Review"
and a character vector of label data to the file.
filename = fullfile("source","timesTableGame.m"); newLabel = addLabel(proj,filename,"Review","To Review","Whole team design review")
newLabel =
Label with properties:
File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
DataType: 'char'
Data: 'Whole team design review'
Name: "To Review"
CategoryName: "Review"
Alternatively, you can set or change label data using theData
property.
myfile = findFiles(proj,filename,OutputFormat="ProjectFile"); mylabel = myfile.Labels(2); mylabel.Data = "Final review";
Input Arguments
proj
— Project
matlab.project.Project
object
Project, specified as a matlab.project.Project
object.
projectFiles
— Project files to label
cell array of character vectors | string array | array of ProjectFile
objects
Project files to label, specified as a cell array of character vectors, a string array, or an array of ProjectFile
objects. The file must be in the project root folder.
fileObject
— Object of project file to label
ProjectFile
object
Object of the file to label, specified as a ProjectFile
object. You can get the ProjectFile
object by examining the project Files
property (proj.Files
) or by using findFiles
to find a file by name. The file must be in the project.
categoryName
— Name of category for label
character vector | string scalar
Name of the category for the label, specified as a character vector or string scalar.
labelName
— Name of label
character vector | string scalar | LabelDefinition
object
Name of the label to attach, specified as a character vector, string scalar, or as a LabelDefinition
object returned by thefile.Label
property or the findLabel function. You can specify a new label name that does not already exist in the project.
labelData
— Data to attach to label
character vector | string scalar | numeric
Data to attach to the label, specified as a character vector, a string scalar, or a numeric value. Data type depends on the label definition. Get a label to examine its DataType
property usingfile.Label
or findLabel
.
Version History
Introduced in R2019a
R2024b: Add label to a file set
Starting in R2024b, you can use theaddLabel(proj,filename,categoryName,labelName)
syntax to add a label to multiple files at the same time. See Attach a Label to a Subset of Files.