Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How do I load variables required in my Simulink model to the MATLAB workspace?


Date Last Modified: Tuesday, September 15, 2009
Solution ID:   1-15R59
Product:   Simulink
Reported in Release:   R12.1
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I load variables required in my Simulink model to the MATLAB workspace?

Problem Description:

When I load the Simulink demo "f14" by typing f14 from in the MATLAB command window, a Simulink model window is created and several variables are created in the MATLAB workspace. How are these variables created in the MATLAB workspace?

In general, how do I automatically load variables required in my Simulink model to the MATLAB workspace?

Solution:

You can use the model's callbacks to load MAT files or to run MATLAB files. From the model explorer, you navigate to Model – Callbacks and place such commands here. Alternatively, you can set these model callbacks programmatically by use of the SET_PARAM command as shown below for the f14 model.

In Simulink 1.3c, this is done in the f14 model with the following command:

set_param('f14','Load callback','f14dat')

This command executes the M-file f14dat.m that generates all the variables necessary in the MATLAB Workspace for running the f14 model. When you type 'who' at the MATLAB prompt after bringing up the f14 model you will see the variables created in the MATLAB Workspace.

From Simulink 2.x and later, this can be done by creating a PreLoadFcn. For more information on Model Callback Routines, please see Technical Note 1818 at the following URL:

http://www.mathworks.com/support/tech-notes/1800/1818.shtml

In particular, the PreLoadFcn is at the following URL:

http://www.mathworks.com/support/tech-notes/1800/1818.shtml#preloadfcn

You should also review Tech Note 1903 for general information on using the Command Line Functionality for Simulink:

http://www.mathworks.com/support/tech-notes/1900/1903.shtml

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page