In this example, you prepare a model to work with Simulink® Compiler™, develop and compile the script, and then deploy it as a standalone application.
Compiler uses rapid accelerator simulation targets to generate an executable to submit
a Simulink model. Simulink
Compiler only supports models which can run in rapid accelerator mode. To set the
simulation mode of the model to rapid accelerator, use the model parameter
SimulationInput object. To
enable simulation deployment of the model, your model must be supported by the Rapid
Accelerator mode correctly.
Compiler only supports
sim function syntax that takes
Simulink.SimulationInput object and returns
If callbacks are present in the model, they are called during the build time of the application. However, once the application or the script is deployed, these callbacks are not invoked.
After preparing the model, write the script that you would like to deploy. In this example, we use a model and change one of the tunable parameters in the script.
In the MATLAB® Editor, create a function
deployedScript. In this function,
Simulink.SimulationInput object for the model,
sldemo_suspn_3dof and change the value of
setVariable method of the
object. To ensure that the model runs in rapid accelerator mode, set the
Rapid through the
setModelParameter method of the
Simulink.SimulationInput object or use the
simulink.compiler.configureForDeployment function as shown
The variables modified in the simulations can be in the base workspace or in the top model workspace.
function deployedScript() in = Simulink.SimulationInput('sldemo_suspn_3dof'); in = in.setVariable('Mb', 1000); in = simulink.simulatio.configureForDeployment(in); out = sim(in); end
Save the function as a
Before compiling the script that you want to deploy, ensure that the files for the model
and script, in this case
sldemo_suspn_3dof and the
deployedScript.m, are included on the MATLAB search path. To compile
the script, use the
mcc command with the script name. To learn more about
mcc command, see
mcc -m deployedScript.m
Compiler automatically packages the dependencies in the model and the deployed
scripts. If the command
mcc cannot find a dependency, you might see errors.
If you see the error "Unable to resolve the name
Simulink.SimulationInput", check that the model is on the
If the dependent files are located in another directory, attach them by using
-a. For example,
mcc -m scriptName.m -a
To run the deployed executable, you need an appropriate runtime environment. To install the MATLAB Runtime, see https://www.mathworks.com/products/compiler/matlab-runtime.html.
You can run the deployed application only on the platform that the deployed application was developed on.
Run the deployed application from the Windows command prompt. Running the deployed application from the command prompt enables the application to print diagnostic messages in the command prompt when it encounters errors. These messages can be a helpful tool in troubleshooting the problem.