Main Content

addLabel

Attach label to project file

Description

addLabel(proj,projectFiles,categoryName,labelName) attaches the specified label in the specified category to the files projectFiles in the project proj.

example

addLabel(proj,projectFiles,labelName) 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,projectFiles,categoryName,labelName,labelData) attaches the label with the specified text or numeric data to the files projectFiles. You cannot add label data to built-in labels.

example

addLabel(fileObject,categoryName,labelName) attaches the specified label in the specified category to the specified file.

addLabel(fileObject,categoryName,labelName,labelData) 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

collapse all

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 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.

files = proj.Files;

Attach the label "R2024b" to all files in the project.

addLabel(proj,files,"Classification","R2024b");

In the project Files view, the Classification column displays the label R2024b for every file in the project.

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 the Data property.

myfile = findFiles(proj,filename,OutputFormat="ProjectFile");
mylabel = myfile.Labels(2);
mylabel.Data = "Final review";

Input Arguments

collapse all

Project, specified as a matlab.project.Project object.

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.

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.

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

Name of the label to attach, specified as a character vector, string scalar, or as a LabelDefinition object returned by the file.Label property or the findLabel function. You can specify a new label name that does not already exist in the project.

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 using file.Label or findLabel.

Version History

Introduced in R2019a

expand all