mdlref_basic.mdl | Open this Model |
Basic Model Reference Demonstration
This tutorial introduces some Model Reference concepts and demonstrates the feature's basic usage. It walks you through simulation and Real-Time Workshop code generation of a model that references another model multiple times.
During this demonstration, Simulink and Real-Time Workshop generate code in a Simulink project directory created in the current working directory. If you do not want to (or if you cannot) generate files in this directory, you should change your working directory.
Real-Time Workshop is required to generate Model Reference RTW target to be deployed in standalone applications.
If you plan to alter the demonstration models:
Preserve the demo in its original state by copying the following files in your MATLAB installation directory without changing their names to a different directory:
Change your current working directory to the directory to which you copied the files.
Continue with the demonstration.
If you haven't already opened it, open the demo model
mdlref_basic. This
model contains three Model blocks:
CounterA,
CounterB and
CounterC. These blocks reference the same model
mdlref_counter.
The mdlref_counter
model is a separate model and it is not a subsystem of mdlref_basic
.
Model Reference has several advantages over subsystems:
Simulation of a model that references other models requires the generation of code and
a binary file called the Simulation Target for each unique referenced model. For this demonstration,
a simulation target is built for the mdlref_counter
model.
You can create the Simulation Target by any of the following actions:
mdlref_basic
.
mdlref_basic
.
slbuild('mdlref_counter','ModelReferenceSimTarget')
.
Remarks:
mdlref_basic
. Note that the Model
blocks inherited different sample times. The Model Blocks inherit their sample times if the referenced model does not
explicitly specify a sample time. You can
turn off the sample time colors.
When a standalone executable for mdlref_basic
is created, first the code and binaries for the RTW Target of
mdlref_counter
are generated. The necessary RTW Targets are built if they are not up-to-date.
You can build of the RTW target for mdlref_counter
and the standalone executable
for mdlref_basic
by any of the following actions:
mdlref_basic
.
slbuild('mdlref_counter','ModelReferenceRTWTarget')
to create the RTW Target for mdlref_counter
and then building mdlref_basic
.
mdlref_basic
,
build mdlref_basic
.
Remarks:
mdlref_counter
is built, subsequent builds of mdlref_basic
do not trigger a rebuild of mdlref_counter
unless mdlref_counter
changes.
mdlref_counter
is reused. RTW
Targets have reusable code.
mdlref_basic
has a link to the HTML report of the generated code for mdlref_counter
in the
Referenced Model section.
find_system('type','block_diagram')
. The referenced model is not listed since
it is not loaded.
find_system('type','block_diagram')
again. The referenced model is listed.