View and Run Program Code Generated by SimBiology Model Analyzer
You can generate MATLAB® code for analysis programs in SimBiology Model Analyzer and run the code at the command line. The following example shows how to generate code for a simulation program, export the necessary inputs for the program to the MATLAB workspace, and run the code.
Open Bioavailability Project
The Bioavailability.sbproj
file contains a simulation program that you
can open directly in the Model Analyzer app. For details about the model, see Estimate the Bioavailability of a Drug.
At the MATLAB command line, enter:
simBiologyModelAnalyzer("Bioavailability.sbproj");
Generate Code for Simulation Program
In the Browser panel, double-click Simulation to open the simulation program. Note that your panel can look slightly different than the screen shot below if you are in the Workspace view of the browser.
The program shows the details about the simulation, such as the model, the dose being used, and simulation stop time.
In the Browser panel, right-click Simulation and select
View Program Code
.It opens an untitled MATLAB function file containing the code for the program. Save the file to a local directory in your computer using the default file name (
runprogram.m
).
Export Input Arguments
Before you can run the generated code, you need to export the input arguments needed for the program code to your MATLAB workspace.
In the Browser panel, right-click Simulation and
select Export Arguments for Program Code
.
Use the variable name args
for the program arguments.
Run Program Code and Plot Results
In the MATLAB workspace, go to the directory where you saved
runprogram.m
. One way is to right-click the file name in the MATLAB Editor and selectChange Current Folder to
.Run the generated code.
programResults = runprogram(args{:})
programResults = struct with fields: input: [1×1 struct] output: [1×1 struct]
The returned output
programResults
is a structure with two fields:input
andoutput
. Theinput
contains a structure with the fields —model
,cs
(simulation settings),variants
, anddoses
— that were used to run the program. Theoutput
contains a structure with the simulationresults
.Plot the simulation results.
sbioplot(programResults.output.results)