deploy a simbiology exported model -凯发k8网页登录
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™.
overview
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
compiler.build.standaloneapplication
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
).
accelerate(exportedmodel);
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 = compiler.build.standaloneapplicationoptions(appfile,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 compiler.build.standalonewindowsapplication(opts); else compiler.build.standaloneapplication(opts); end
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)
references
[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
- develop apps using app designer
- deploy web app (matlab compiler)