Documentation

addLabel

(Not recommended) Attach label to project file

simulinkprojectis not recommended. UsecurrentProjectoropenProjectinstead. For more information, seeCompatibility Considerations.

Description

example

addLabel(file,categoryName,labelName)attaches the specified labellabelNamein the categorycategoryNameto the file.

example

addLabel(file,categoryName,labelName,labelData)attaches the label with datalabelData.

Examples

collapse all

Open the airframe project and create a project object.

sldemo_slproject_airframe; proj = simulinkproject;

Get a particular file by name.

myfile = findFile(proj,'models/AnalogControl.slx')
myfile = ProjectFile with properties: Path: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.slx' Labels: [1x1 slproject.Label] Revision: '2' SourceControlStatus: Unmodified

Get theLabelsproperty of the file.

myfile.Labels
ans = Label with properties: File: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.slx' Data: [] DataType: 'none' Name: 'Design' CategoryName: 'Classification'

Attach the label'Artifact'to the file.

addLabel(myfile,'Classification','Artifact')
ans = Label with properties: File: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.slx' Data: [] DataType: 'none' Name: 'Artifact' CategoryName: 'Classification'

Index into the Labels property to get the label attached to this file.

reviewlabel = myfile.Labels(1)
reviewlabel = Label with properties: File: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.slx' Data: [] DataType: 'none' Name: 'Artifact' CategoryName: 'Classification'

Detach the new label from the file.

removeLabel(myfile,reviewlabel)

Attach the'Classification'category label'Utility'to all files in the project that have the.mfile extension.

Open the airframe project and create a project object.

sldemo_slproject_airframe; proj = simulinkproject;

Get the list of files.

files = proj.Files;

Loop through each file. If a file has the extension.m, attach the label'Utility'.

forfileIndex = 1:numel(files) file = files(fileIndex); [~, ~, fileExtension] = fileparts(file.Path);ifstrcmp(fileExtension,'.m') addLabel(file,'Classification','Utility');endend

In the ProjectFilesview, theClassificationcolumn displays the labelUtilityfor each.mfile in theutilitiesfolder.

Open the airframe project and create a project object.

sldemo_slproject_airframe; proj = simulinkproject;

Create a new category'Review'.

createCategory(proj,'Review','char');

新类别,创建一个标签'To Review'.

reviewCategory = findCategory(proj,'Review');createLabel(reviewCategory,'To Review');

Get a particular file by name.

myfile = findFile(proj,'models/AnalogControl.slx')
myfile = ProjectFile with properties: Path: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.slx' Labels: [1x1 slproject.Label] Revision: '2' SourceControlStatus: Unmodified

Attach the label'To Review'and a character vector of label data to the file.

addLabel(myfile,'Review','To Review','Whole team design review')

Index into the Labels property to get the second label attached to this particular file, and see the label data.

myfile.Labels(2)
ans = Label with properties: File: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.slx' Data: 'Whole team design review' DataType: 'char' Name: 'To Review' CategoryName: 'Review'

In the ProjectFilesview, for theAnalogControl.slxfile, theReviewcolumn displays theTo Reviewlabel with label data.

Alternatively, you can set or change label data using the data property.

mylabel = myfile.Labels(2); mylabel.Data ='Final review';

Input Arguments

collapse all

File to attach the label to, specified as a file object. You can get the file object by examining the project’s Files property (proj.Files), or usefindFileto find a file by name. The file must be in the project.

Name of the category for the label, specified as a character vector.

Name of the label to attach, specified as a character vector or a label definition object returned by thefile.Labelproperty orfindLabel. You can specify a new label name that does not already exist in the project.

Data to attach to the label, specified as a character vector or numeric. Data type depends on the label definition. Get a label to examine itsDataTypeproperty usingfile.LabelorfindLabel.

Compatibility Considerations

expand all

Not recommended starting in R2019a

Introduced in R2013a