Main Content

createCategory

Create category of project labels

Description

createCategory(proj,categoryName) creates a new category of labels in the specified project.

example

createCategory(proj,categoryName,dataType) also specifies the type of data to store in labels of the new category. For more information on data types, see Fundamental MATLAB Classes.

example

createCategory(proj,categoryName,dataType,"single-valued") specifies a single-valued category, where you can attach only one label from the category to a file. If you do not specify a single-valued category, then you can attach multiple labels from the category to a file.

example

category = createCategory(___) returns the new category as a Category object. Use this syntax with any of the previous input argument combinations.

example

Examples

collapse all

Create a new category of labels to indicate the owner of a file, and attach a new label from it to a file, along with label data.

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, to indicate which engineer owns a file. These labels have the char data type for attaching character vector data.

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

Use the findCategory function to get the new category.

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";
disp(label)
Label with properties:

            File: [1x80 char]
            Data: "Maintenance responsibility"
        DataType: 'char'
            Name: "Tom"
    CategoryName: "Engineers"

Create a category of labels with the double data type, used for numeric data.

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. Specify "double" as the data type. This is the data type MATLAB® uses for numbers by default.

coverageCategory = createCategory(proj,"Coverage","double")
coverageCategory = 

  Category with properties:

                Name: "Coverage"
            DataType: 'double'
    LabelDefinitions: []

Create a label in the new category and add it to a file in the project.

createLabel(coverageCategory,"Test");
myfile = findFile(proj,"source/timesTableGame.m");
label = addLabel(myfile,"Coverage","Test");

Add numeric data to the label.

label.Data = 80
label = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'double'
            Data: 80
            Name: "Test"
    CategoryName: "Coverage"

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 category of labels for file ownership, and specify single-valued to restrict only one label in the category per file.

engineersCategory = createCategory(proj,"Engineers","char", "single-valued");

Create a label in the new category and add it to a file in the project.

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

  Label with properties:

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

Create a second label in the new category and add it to the same file in the project. MATLAB replaces the first label with the new one.

createLabel(engineersCategory,"Harry");
addLabel(myfile,"Engineers","Harry")
ans = 

  Label with properties:

            File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
        DataType: 'char'
            Data: []
            Name: "Harry"
    CategoryName: "Engineers"

Check to see if the first label is still attached to the file.

findLabel(myfile,"Engineers","Tom")
ans = 

  0×0 Label array with properties:

    File
    DataType
    Data
    Name
    CategoryName

Input Arguments

collapse all

Project, specified as a matlab.project.Project object. Use currentProject to create a project object from the currently loaded project.

Name of the category of labels to create, specified as a character vector or string scalar.

The type of data to store in labels in the new category, specified as a character vector or string scalar.

Output Arguments

collapse all

Category, returned as a Category object.

Tips

After you create a new category, you can create labels in the new category using the createLabel function.

Version History

Introduced in R2019a