findLabel

(Not recommended) Get project file label

simulinkproject is not recommended. Use currentProject or openProject instead. For more information, see Compatibility Considerations.

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 or files. 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

collapse all

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 Utility.

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

Find all the files with the label Utility and add them to a list returned in utility_files_to_review.

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

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

Get a label by name.

label = findLabel(myfile,'Classification','Design');

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

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: 'Classification'
            DataType: 'none'
    LabelDefinitions: [1x8 slproject.LabelDefinition]

Get a label definition.

ld = findLabel(category,'Design')
ld = 

  LabelDefinition with properties:

            Name: 'Design'
    CategoryName: 'Classification'

Input Arguments

collapse all

File to search the labels of, specified as a file object or an array of file objects. 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 in the project.

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

Name of the label to get, specified as a character vector.

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

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

Output Arguments

collapse all

Label, returned as a label object.

Compatibility Considerations

expand all

Not recommended starting in R2019a

Introduced in R2013a