Main Content

createLabel

Create project label

Description

labelDefinition = createLabel(category,newLabelName) creates a new label, in the specified category. Use this syntax if you previously got a Category object by accessing a Categories property, for instance by using syntax like proj.Categories(1).

example

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;

Get the first existing category.

cat = proj.Categories(1)
cat = 

  Category with properties:

                Name: "Classification"
        SingleValued: 1
            DataType: "none"
    LabelDefinitions: [1×7 matlab.project.LabelDefinition]

Define a new label in the category.

createLabel(cat,"Future");

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 of labels called "Engineers" which can be used to denote file ownership in a project. These labels have the char datatype for attaching character vector data.

createCategory(proj,"Engineers","char");

Get the new category by name using the findCategory function

engineersCategory = findCategory(proj,"Engineers");

Create labels in the new category.

createLabel(engineersCategory,"Tom");
createLabel(engineersCategory,"Harry");

Attach one of the new labels to a file in the project.

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

Get the label and add data.

label = findLabel(myfile,"Engineers","Tom");
label.Data = "Maintenance responsibility"
  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'char'
            Data: "Maintenance responsibility"
            Name: "Tom"
    CategoryName: "Engineers"

Input Arguments

collapse all

Category for the new label, specified as a Category object. Get the Category object by accessing a Categories property, using a syntax like proj.Categories(1), or use the findCategory function. To create a new category, use the createCategory function.

The name of the new label, specified as a character vector.

Output Arguments

collapse all

Label definition, returned as a labelDefinition object.

Tips

  • To create and attach a new label in an existing category using a single step, use addLabel instead.

  • To create a new category of labels, use createCategory first.

Version History

Introduced in R2019a