Main Content

Deploy a SimBiology Exported Model

This example shows how to deploy a graphical application that simulates a SimBiology® model. The example model is the Lotka-Volterra reaction system as described by Gillespie [1], which can be interpreted as a simple predator-prey model.

This example requires MATLAB Compiler™.


You can create standalone SimBiology applications using MATLAB Compiler and the SimBiology exported model. To make your application compatible with MATLAB Compiler, do the following:

  • Create an exported model, using the model's export method.

  • Accelerate the model (optional).

  • Save the model to a MAT file.

  • Ensure your application loads the model from the MAT file.

  • Add the %#function pragma to the application's top-level function.

  • Call the function, explicitly adding the MAT file and the exported model's dependent files to the application.

Load the Model

sbioloadproject lotka m1

Create the Exported Model

exportedModel = export(m1);

Accelerate the Model

Acceleration requires a correctly configured MEX compiler (see the documentation for mex -setup).


Save the Exported Model

Save the model in a MAT file.

save exportedLotka exportedModel

Compile and Build Standalone Application

The code that builds an application for the purposes of this example is provided in simulateLotkaGUI.m.The app lets you vary the Lotka-Volterra model parameter values with sliders and plots the prey and predator populations. It uses the exported model from the MAT file. The code also contains the following %#function pragma, which tells the MATLAB Compiler that the application uses a SimBiology exported model: %#function SimBiology.export.Model.

appfile = fullfile(matlabroot,"toolbox","simbio","simbiodemos","simulateLotkaGUI.m");

If you want to see what the app looks like, you can open the file and hit Run on the toolstrip.

Next, specify the list of dependency files that are needed for the application. This list includes the MAT file containing the exported model and any files listed in the DependentFiles property of the exported model.

appDependencies = ["exportedLotka.mat";string(exportedModel.DependentFiles)'];

Define the standalone application build options that contain the app file and dependency files.

opts =,AdditionalFiles=appDependencies);

Create a deployable standalone application using MATLAB Compiler. It creates a folder named simulateLotkaGUIstandaloneApplication that contains an executable file that you can deploy.

if ispc;

Compile Using mcc As an Alternative Approach

You can also use the mcc command to build the standalone application. Note that the MAT file must be loaded into the workspace before mcc is called, so that the exported model's files are available for deployment.

To speed compilation, use the option -N -p simbio, which informs mcc that the deployed application does not depend on any additional toolboxes. For the purposes of this example, programmatically construct the mcc command.

mccCommand = ['mcc -m simulateLotkaGUI.m -N -p simbio -a exportedLotka.mat ' ...
     sprintf(' -a %s', exportedModel.DependentFiles{:})];
% eval(mccCommand) 


[1] Gillespie, Daniel T. “Exact Stochastic Simulation of Coupled Chemical Reactions.” The Journal of Physical Chemistry 81, no. 25 (December 1977): 2340–61.

See Also

| (MATLAB Compiler) | (MATLAB Compiler)

Related Topics