(Not recommended) Attach label to project file
simulinkproject
is not recommended. Use currentProject
or openProject
instead. For more information, see Compatibility Considerations.
addLabel(
attaches the specified label file
,categoryName
,labelName
)labelName
in the category
categoryName
to the file.
addLabel(
attaches the label with data file
,categoryName
,labelName
,labelData
)labelData
.
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 the Labels
property 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
.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 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.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 Project Files view, for the
AnalogControl.slx
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';
file
— File to attach label toFile 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.
categoryName
— Name of category for labelName of the category for the label, specified as a character vector.
labelName
— Name of labelName 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.
labelData
— Data to attach to labelData 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
.
Not recommended starting in R2019a
Starting in R2019a, instead of simulinkproject
and related functions,
use the currentProject
or openProject
functions in MATLAB®. The Simulink® project API will continue to be supported, but, after R2019a, new features
might be available only if you use the new MATLAB project API. There are no plans to remove the Simulink project API at this time.
The new MATLAB project API is part of the R2019a functionality enabling you to use projects in MATLAB, with or without Simulink. You can now share projects with users who do not have Simulink.