Contenuto principale

createLabel

R2026b

Create project label

Description

labelDefinitions = createLabel(category,LabelNames) creates new labels, in the specified category. Use this syntax if you previously got a Category object by using the findCategory function.

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","Harry"]);

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

label = addLabel(myfile,"Engineers","Tom");

Get the label and add data.

label.Data = "Maintenance responsibility"
  Label with properties:

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

Open the Times Table App project. Use currentProject to create a project object from the currently loaded project.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Convert the project to use the TOML definition file type.

projRoot = proj.RootFolder
close(proj)
matlab.project.convertDefinitionFiles(projRoot.RootFolder, "Toml")
openProject(proj)

Create a new category of labels named "MyCategory".

category = proj.createCategory("MyCategory");

Create a label named "MyLabel" in the new category.

label = category.createLabel("MyLabel");

Create a pattern to automatically label all existing and future files inside the utilities folder with the "MyLabel" label.

label.FilePatterns = ["utilities/*"];

All files in the utilities folder are attached with the "MyLabel" label

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 labels, specified as a string array or a cell array of character vectors.

Output Arguments

collapse all

Labels definition, returned as an array of labelDefinition objects.

A LabelDefinition object has these properties:

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

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

Since R2026b

File patterns associated with the label, specified as an array of strings.

By setting this property, the software labels all the files associated with the specified pattern. For more information, see Create a Label Pattern to Automatically Label Files.

To learn more about pattern matching, see Match Files and Folders Using Patterns.

Dependencies

To set this property, the project containing this label must use the TOML definition file type.

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

expand all