findLabel

Get Simulink Project file label

Syntax

  • label = findLabel(file,categoryName,labelName) example
  • label = findLabel(file,labelDefinition) example
  • label = findLabel(category,labelName) example

Description

example

label = findLabel(file,categoryName,labelName) returns the label and its attached data for the label labelName in the category categoryName that is attached to the specified file. Use this syntax when you know the label name and category.

example

label = findLabel(file,labelDefinition) returns the file label and its attached data for the label name and category specified by labelDefinition. Use this syntax if you previously got a labelDefinition by accessing a Labels property, e.g., using a command like myfile.Labels(1).

example

label = findLabel(category,labelName) returns the label definition of the label in this category specified by labelName. Returns an empty array if the label is not found.

Examples

expand all

Find Files with the Label To Review

Find all project files with a particular label.

Open the airframe project and create a project object.

sldemo_slproject_airframe;
proj = simulinkproject;

Get the list of project 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

Find all the files with the label To Review and add them to a list returned in files_to_review.

files_to_review = {};
for jj=1:numel(files)
    this_file = files(jj);
    
       label = findLabel(this_file,'Review','To Review');
      
       if ( ~isempty(label))
        % This is a file labeled 'To Review'. Add to the 
        % list of files to review.
        files_to_review = [files_to_review; this_file];         
           end
end

Find a Label by Name or Definition

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');

Get a label by name.

label = findLabel(myfile,'Review','To Review');

Alternatively, examine the Labels property of the file to get an array of Label objects, one for each label attached to the file.

labels = myfile.Labels

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

labeldefinition = myfile.Labels(1)

After you get the label definition from the Labels property, you can use it with findLabel.

label = findLabel(myfile,labeldefinition);

Find Labels by Name or Definition

Open the airframe project and create a project object.

sldemo_slproject_airframe;
proj = simulinkproject;

Get a category.

category = proj.Categories(1)
category = 

  Category with properties:

                Name: 'Review'
            DataType: 'char'
    LabelDefinitions: [1x4 slproject.LabelDefinition]

Get a label definition.

ld = findLabel(category,'To Review')
ld = 

  LabelDefinition with properties:

            Name: 'To Review'
    CategoryName: 'Review'

Input Arguments

expand all

file — File to search labels offile object

File to search the labels of, specified as a file object. You can get the file object by examining the project's Files property (proj.Files), or use findFile to get a file by name. The file must be within the root folder.

categoryName — Name of categorystring

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

labelName — Name of labelstring

Name of the label to get, specified as a string.

labelDefinition — Name of labellabel definition object

Name of the label to get, specified as a label definition object returned by the file.Label property.

category — Category of labelscategory object

Category of labels, specified as a category object. Get a category object from the proj.Categories property or by using findCategory.

Output Arguments

expand all

label — Labellabel object

Label, returned as a label object.

See Also

Functions

Was this topic helpful?