mdlref_paramargs.mdl | Open this Model |
Model Reference Parameter Arguments Demonstration
This demonstration illustrates the setup to pass parameter values to instances of a referenced model. (For a brief introduction to Model Reference, run the Basic Model Reference Demonstration.)
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 binaries 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 Simulink model
mdlref_paramargs. This
model contains three Model blocks:
CounterA,
CounterB and
CounterC. These blocks reference the same model
mdlref_counter_paramargs.
The referenced model has two parameters that need to be set. These are upper_saturation_limit
and lower_saturation_limit
.
In each Model Block, counter_with_parameters
is called with different values for each parameter.
The demonstration prepares mdlref_counter_paramargs
to accept parameter arguments and mdlref_paramargs
to pass different parameter values,
step by step in the following order:
mdlref_counter_paramargs
is prepared. mdlref_paramargs
is prepared.
After preparing the models, the standalone executable for the mdlref_paramargs
is created.
mdlref_counter_paramargs
The parameters of the referenced model upper_saturation_limit
and lower_saturation_limit
are defined and initialized
in the model workspace of mdlref_counter_paramargs
.
The model workspace behaves like any other MATLAB workspace. In this workspace, you can create variables and execute MATLAB commands.
You can define and initialize the parameters lower_saturation_limit
and upper_saturation_limit
from the MATLAB prompt.
The M commands can be saved. You can also upload the model workspace from the MDL-file or from a MAT-file.
In addition, the parameters can be saved to a MAT or the MDL-file. In this demo, the parameters are initialized from a MAT-File called
mdlref_counter_paramargs_init.mat
.
First open the model workspace in the Model Explorer.
Choose the type of the Data source
located in the Workspace data
section . In this demo, the type is a MAT-File.
Then, enter the path and the name of the file in the File name field. This option is only required if a MAT-file is chosen as the data source.
The file used in this demonstration is mdlref_counter_paramargs_init.mat
Use the Re-initialize Workspace
button to load and update the model workspace.
In the Model Explorer fill in the Model arguments
field. For this demonstration, the value is 'lower_saturation_limit,upper_saturation_limit'.
Save the copy of mdlref_counter_paramargs
if you have altered it.
Obtain the model workspace from the MATLAB prompt as follows:
mdlWS = get_param('mdlref_counter_paramargs', 'ModelWorkspace')
Register the data source with the following commands:
Upload the variables into the referenced model's workspace:
Set the name of the parameter arguments with the following command:
Save the copy of mdlref_counter_paramargs
if you have altered it.
mdlref_paramargs
Set the values of the parameters upper_saturation_limit
and lower_saturation_limit
in each Model Block.
Save the copy of mdlref_paramargs
if you have altered it.
mdlref_paramargs
to see the effect of different values for the parameters.
mdlref_paramargs
.