Main Content

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

Enter the following command to open the Bioavailability.sbproj file that contains a simulation program. For details about the model, see Estimate the Bioavailability of a Drug.

openExample('simbio/RunProgramSimBiologyModelAnalyzerExample')

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 select Change 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 and output. The input contains a structure with the fields — model, cs (simulation settings), variants, and doses — that were used to run the program. The output contains a structure with the simulation results.

Plot the simulation results.

sbioplot(programResults.output.results)

See Also

Related Topics