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

expand all

Attach a Label to a Project File

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: [1x86 char]
    Labels: [1x1 slproject.Label]

Get the Labels property of the file.

myfile.Labels
ans = 

  Label with properties:

            File: 'C:\work\airframe\models\AnalogControl.mdl'
            Data: []
        DataType: 'none'
            Name: 'Design'
    CategoryName: 'Classification'

Attach the label 'To Review' to the file.

addLabel(myfile,'Review','To Review')
ans = 

  Label with properties:

            File: [1x82 char]
            Data: []
        DataType: 'char'
            Name: 'To Review'
    CategoryName: 'Review'

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

reviewlabel = myfile.Labels(2)
reviewlabel = 

  Label with properties:

            File: 'C:\Temp\project1\airframe\models\AnalogControl.mdl'
            Data: []
        DataType: 'char'
            Name: 'To Review'
    CategoryName: 'Review'

Detach the new label from the file.

removeLabel(myfile,reviewlabel)

Attach a Label to a Subset of Files

Attach the label 'To Review' in the 'Review' category to all files in the project with 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 the file has the extension .m, attach the label To Review.

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

In the Simulink® Project Tool, the label To Review appears in the Review column next to the files in the project utilities folder.

Attach a Label and Label Data to a File

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: [1x86 char]
    Labels: [1x1 slproject.Label]

Attach the label 'To Review' and a string 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:\Temp\project1\airframe\models\AnalogControl.mdl'
            Data: 'Whole team design review'
        DataType: 'char'
            Name: 'To Review'
    CategoryName: 'Review'

In the Simulink Project Tool, the label To Review and the label data appear in the Review column next to the file AnalogControl.mdl.

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

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

Input Arguments

expand all

file — File to attach label tofile object

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 within the root folder.

categoryName — Name of category for labelstring

Name of the category for the label, specified as a string.

labelName — Name of labelstring | label definition object

Name of the label to attach, specified as a string 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.

labelData — Data to attach to labelstring | numeric

Data to attach to the label, specified as a string or numeric. Data type depends on the label definition. Get a label to examine its DataType property using file.Label or findLabel.

Was this topic helpful?