Why do I get errors when I simulate a model that contains a referenced model using the SIM command from a MATLAB function and obtain parameter values from the current workspace in Simulink 7.2 (R2008b)?

10 views (last 30 days)
I want to run a Simulink model from a MATLAB function. The Simulink model contains a model reference block.
However, when I execute the following commands in my MATLAB function:
opt = simset('SrcWorkspace','Current');
sim('MainTest',1,opt);
I get the following error message:
??? Error using ==> RunTheModel at 6
Error due to multiple causes:
--> Error using ==> tlc_c at 116
Error evaluating parameter 'Gain' in
'ReferedTest/Gain': Error using ==> rtwgen
Undefined function or variable 'a'.
--> Error while bringing model references of model
MainTest up to date: Error using ==> tlc_c at 116
Error evaluating parameter 'Gain' in
'ReferedTest/Gain': Error using ==> rtwgen
Undefined function or variable 'a'.
Caused by:
Error using ==> RunTheModel at 6
Error using ==> tlc_c at 116
Error evaluating parameter 'Gain' in
'ReferedTest/Gain': Error using ==> rtwgen
Undefined function or variable 'a'.
Error using ==> RunTheModel at 6
Error while bringing model references of model
MainTest up to date: Error using ==> tlc_c at 116
Error evaluating parameter 'Gain' in
'ReferedTest/Gain': Error using ==> rtwgen
Undefined function or variable 'a'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The ability to define the "Source Workspace" for referenced models is not available in Simulink 7.2 (R2008b).
To work around this limitation, setup the model to obtain parameter values from a MAT-file instead. This can be done by using Model Explorer to set the source of the Model Workspace for the Simulink model to a MAT-file. The MATLAB function / script can then be used to create / modify the MAT-file and execute the following lines of code to load the fresh data into the Model Workspace before running the simulation:
load_system(RefModelName)
hws = get_param(RefModelName, 'modelworkspace');
hws.reload;
Please see the attached files for an example.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!