createCategory - Create category of project labels - MATLAB (original) (raw)
Create category of project labels
Syntax
Description
createCategory([proj](#mw%5Fc4092d60-9abd-4430-94f3-f229b5f627da%5Fsep%5Fmw%5F67855d3a-5501-4c51-aab0-b8f7aeb42e61),[categoryName](#mw%5Fc4092d60-9abd-4430-94f3-f229b5f627da%5Fsep%5Fmw%5Fddd07ae7-a5aa-4eeb-8a67-86d0bd0901cd))
creates a new category of labels in the specified project.
createCategory([proj](#mw%5Fc4092d60-9abd-4430-94f3-f229b5f627da%5Fsep%5Fmw%5F67855d3a-5501-4c51-aab0-b8f7aeb42e61),[categoryName](#mw%5Fc4092d60-9abd-4430-94f3-f229b5f627da%5Fsep%5Fmw%5Fddd07ae7-a5aa-4eeb-8a67-86d0bd0901cd),[dataType](#mw%5Fc4092d60-9abd-4430-94f3-f229b5f627da%5Fsep%5Fmw%5Fd16ac5d3-476a-4479-975e-78af248e6006),"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.
[category](#mw%5Fed14bf5c-8c31-4a2b-b9c1-92890628e4e9) = createCategory(___)
returns the new category as a Category
object. Use this syntax with any of the previous input argument combinations.
Examples
Create New Category of Labels
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 thechar
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 Category for Numeric Labels
Create a category of labels with thedouble
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 =
Label with properties:
File: "C:\myProjects\examples\TimesTableApp\source\timesTableGame.m"
DataType: 'double'
Data: 80
Name: "Test"
CategoryName: "Coverage"
Create Single-Valued Category
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
proj
— Project
matlab.project.Project
object
Project, specified as a matlab.project.Project
object. Use currentProject to create a project object from the currently loaded project.
categoryName
— Name of category
character vector | string scalar
Name of the category of labels to create, specified as a character vector or string scalar.
dataType
— Type of data to store in labels
character vector | string scalar
The type of data to store in labels in the new category, specified as a character vector or string scalar.
Output Arguments
category
— Category object
Category
object
Category, returned as a Category
object.
Tips
After you create a new category, you can create labels in the new category using thecreateLabel function.
Version History
Introduced in R2019a