createLabel - Create project label - MATLAB (original) (raw)
Main Content
Syntax
Description
[labelDefinition](#mw%5Fc1da734e-7514-4efb-84cc-054b442d121d) = createLabel([category](#mw%5Febbc21a3-7661-45b9-b749-867b064e8615),[newLabelName](#mw%5F352e181e-c1ec-4b5b-bf90-bf2371a595e5))
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 likeproj.Categories(1)
.
Examples
Create a New Label
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 =
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");
Create a New Category of Labels for File Ownership
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
category
— Category
Category
object
Category for the new label, specified as a Category
object. Get the Category
object by accessing aCategories
property, using a syntax likeproj.Categories(1)
, or use thefindCategory
function. To create a new category, use the createCategory
function.
newLabelName
— The name of the new label
character vector
The name of the new label, specified as a character vector.
Output Arguments
labelDefinition
— Label definition object
labelDefinition
object
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