Documentation

addLabel

Attach label to Simulink Project file

Syntax

  • addLabel(file,categoryName,labelName)
    example
  • addLabel(file,categoryName,labelName,labelData)
    example

Description

example

addLabel(file,categoryName,labelName) attaches the specified label labelName in the category categoryName to the file.

example

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

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.mdl')
myfile = 

  ProjectFile with properties:

      Path: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.mdl'
    Labels: [1x1 slproject.Label]
  Revision: '2'
SourceControlStatus: Unmodified

Get the Labels property of the file.

myfile.Labels
ans = 

  Label with properties:

            File: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.mdl'
            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.mdl'
            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.mdl'
            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 .m file 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'.

for fileIndex = 1:numel(files)
   file = files(fileIndex);
   [~, ~, fileExtension] = fileparts(file.Path);
   if strcmp(fileExtension,'.m')
       addLabel(file,'Classification','Utility');
   end
end

In the Simulink® Project Files view, the Classification column displays the label Utility for each .m file in the utilities folder.

Open the airframe project and create a project object.

sldemo_slproject_airframe;
proj = simulinkproject;

Create a new category 'Review'.

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

For the new category, create a label 'To Review'.

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

Get a particular file by name.

myfile = findFile(proj,'models/AnalogControl.mdl')
myfile = 

  ProjectFile with properties:

      Path: 'C:\Work\temp\slexamples\airframe\models\AnalogControl.mdl'
    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.mdl'
            Data: 'Whole team design review'
        DataType: 'char'
            Name: 'To Review'
    CategoryName: 'Review'

In the Simulink Project Files view, for the AnalogControl.mdl file, the Review column displays the To Review label 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 use findFile to 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 the file.Label property or findLabel. 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 its DataType property using file.Label or findLabel.

Introduced in R2013a

Was this topic helpful?