Checking File and Model Dependencies
Why Check File and Model Dependencies?
Each Simulink® model requires a set of files to run successfully. These files can include referenced models, data files, S-functions, and other files without which the model cannot run. These required files are called model dependencies. The Dependency Analyzer allows you to analyze a model to determine its model dependencies.
Similarly, Simscape™ files and custom libraries also depend on certain files to build successfully, or to correctly visualize and execute in MATLAB®. These files can include all component files for building a library, domain files, custom image files for blocks or libraries, and so on.
Dependency analysis tools for Simscape files consist of the following command-line options:
simscape.dependency.file
— Return the set of existing full path dependency files and missing files for a single Simscape file, for a specific dependency type.simscape.dependency.lib
— Return the set of existing full path dependency files and missing files for a Simscape custom library namespace. You can optionally specify dependency type and library model file name.simscape.dependency.model
— Return the set of Simscape related dependency files and missing files for a given model containing Simscape and Simulink blocks.
The Dependency Analyzer also includes dependencies for the Simscape blocks present in the model. For more information on the Dependency Analyzer, see Analyze Model Dependencies.
Checking Dependencies of Protected Files
If a namespace contains Simscape protected files, with the corresponding Simscape source files in the same folder, the analysis returns the names of protected files and then analyzes the source files for further dependencies. If the namespace contains Simscape protected files without the corresponding source files, the protected file names are returned without further analysis.
This way, dependency information is not exposed to a model user, who has only protected files. However, the developer, who has both the source and protected files, is able to perform complete dependency analysis.
Checking Simscape File Dependencies
To check dependencies for a single Simscape file, use the function simscape.dependency.file
.
For example, consider the following folder structure:
- +MySimscapeLibrary |-- +MechanicalElements | |-- lib.m | |-- lib.jpg | |-- spring.ssc | |-- spring.jpg | |-- ...
The top-level namespace, +MySimscapeLibrary
, is located in a
folder on the MATLAB path.
To check dependencies for the file spring.ssc
, type the
following at the MATLAB command prompt:
[a, b] = simscape.dependency.file('MySimscapeLibrary.MechanicalElements.spring')
This command returns two cell arrays of strings: array a
,
containing full path names of existing dependency files (such as
spring.jpg
), and array b
, containing names
of missing files. If none of the files are missing, array b
is
empty.
For more information, see the simscape.dependency.file
function
reference page.
Checking Library Dependencies
To check dependencies for a Simscape library namespace, use the function
simscape.dependency.lib
.
For example, to return all dependency files for a top-level namespace
+MySimscapeLibrary
, change your working folder to the folder
containing this namespace and type the following at the MATLAB command prompt:
[a, b] = simscape.dependency.lib('MySimscapeLibrary')
If you are running this command from a working folder inside the namespace, you can omit the library name, because it is the only argument, and type:
[a, b] = simscape.dependency.lib
This command returns two cell arrays of strings: array a
,
containing full path names of all existing dependency files and array
b
, containing names of missing files. If none of the files
are missing, array b
is empty.
To determine which files are necessary to share the library namespace, type:
[a, b] = simscape.dependency.lib('MySimscapeLibrary',simscape.DependencyType.Simulink)
In this case, the arrays a
and b
contain all
files necessary to build the library, run the models built from its blocks, and
visualize them correctly.
Checking Model Dependencies
To perform a complete dependencies check, open the model. On the Modeling tab of the Simulink Toolstrip, in the Design section, click Dependency Analyzer. For more information, see Analyze Model Dependencies.
To check dependencies on Simscape blocks and files only, use the function
simscape.dependency.model
. For example, open the model
dc_motor
and type:
[a b c d] = simscape.dependency.model('dc_motor')
This command returns two cell arrays of strings and two lists of structures. Array
a
contains full path names of all existing dependency files.
Array b
contains names of missing files. Structure lists
c
and d
indicate reference types for
existing and missing reference files, respectively. Each structure includes a field
'names'
as a list of file names causing the reference, and a
field 'type'
as the reference type for each file. Two reference
types are used: 'Simscape component'
indicates reference from a
model block. 'Simscape'
indicates reference from a file.
If none of the files are missing, array b
and list
d
are empty.