sbioplot
Plot simulation results in one figure
Description
sbioplot(
plots simulation results by calling the function handlesd
,fcnHandle
,xArgs
,yArgs
,Name,Value
)fcnHandle
with inputssd
,xArgs
, andyArgs
, and uses additional options specified by one or more name-value pair arguments. For example, you can specify the x-label and y-label of the plot.xArgs
andyArgs
must be cell arrays or string vectors of the names of the states to plot.
Examples
Plot Selected States from Simulation Data
Plot the prey versus predator data from the stochastically simulated lotka model by using a custom function (plotXY
).
Load the model. Set the solver type to SSA to perform stochastic simulations, and set the stop time to 3.
sbioloadprojectlotka; cs = getconfigset(m1); cs.SolverType ='SSA'; cs.StopTime = 3; rng('default')% For reproducibility
Set the number of runs and usesbioensemblerun
for simulation.
numRuns = 2; sd = sbioensemblerun(m1,numRuns);
Plot the simulation data. By default,sbioplot
shows the time plot of each species for each run.
sbioplot(sd);
Plot selected states against each other; in this case, plot the prey population versus the predator population. Use the functionplotXY
(shown at the end of this example) to plot the simulated y1 (prey) data versus the y2 (predator) data. Specify the function as a function handle.
If you use the live script file for this example, theplotXY
来电显示n is already included at the end of the file. Otherwise, you must define theplotXY
来电显示n at the end of your .m or .mlx file or add it as a file on the MATLAB path.
sbioplot(sd,@plotXY,{'y1'},{'y2'},'xlabel','y1','ylabel','y2','title','Prey versus Predator');
Define plotXY Function
sbioplot accepts a function handle for a function with the signature:
来电显示n [handles,names] = functionName(sd,xArgs,yArgs)
.
TheplotXY
来电显示n plots two selected states against each other. The first inputsd
is the simulation data (SimBiologySimData
object or vector of objects). In this particular example, xArgs is a cell array containing the name of the species to be plotted on the x-axis, and yArgs is a cell array containing the name of the second species to be plotted on the y-axis. However, you can use the inputs xArgs and yArgs in any way inyourcustom plotting function. The function returns处理
, an array of function handles to the line plots, andnames
, a cell array of character vectors shown on the nodes that are children of aRunnode in a hierarchical display.
来电显示n[handles,names] = plotXY(sd,xArgs,yArgs)% Select simulation data for each state from each run.xData1 = selectbyname(sd(1),xArgs); xData2 = selectbyname(sd(2),xArgs); yData1 = selectbyname(sd(1),yArgs); yData2 = selectbyname(sd(2),yArgs);% Plot the species against each other.fH1 = plot(xData1.Data,yData1.Data); fH2 = plot(xData2.Data,yData2.Data);% The first output, handles, is a two-dimensional array of handles of the line plots. It must be of size M x N,% where M is the number of line plots for each run and N is the number of runs.处理= [fH1,fH2];% The second output, names, must be a one-dimensional cell array of character vectors.% Its length must be equal to the number of rows in handles, and the texts are displayed on the% nodes that are children of a Run node.names = {'y1 vs y2'};end
Input Arguments
fcnHandle
—Function to generate line plots
来电显示n handle
Function to generate line plots, specified as a function handle. For an example of a custom function to plot selected species from simulation data, seePlot Selected States from Simulation Data.
The function must have the signature:
来电显示n [handles,names] = functionName(sd,xArgs,yArgs)
.
The inputssd
,xArgs
, andyArgs
are the same inputs that you pass in when you callsbioplot
.
The first output处理
is a two-dimensional array of handles of the line plots generated by the function. Its size must beP-by-R, wherePis the number of line plots, andRis the number of runs.
The second outputnames
is a one-dimensional cell array of character vectors containing the names to be displayed on the nodes that are children of aRunnode in a hierarchical display. The length ofnames
must be equal to the number of rows in处理
.
Example:@plotXY
Data Types:来电显示n_handle
xArgs
—State names
字符串向量|cell array of character vectors
State names to plot, specified as a string vector or cell array of character vectors. For instance, you can usexArgs
to represent the states to be plotted on thex-axis of your custom plot.
This argument corresponds to the second input of the function referenced byfcnHandle
.
Example:{'y1'}
Data Types:cell
yArgs
—State names
字符串向量|cell array of character vectors
State names to plot, specified as a string vector or cell array of character vectors. For instance, you can useyArgs
to represent the states to be plotted on they-axis of your custom plot.
This argument corresponds to the third input of the function referenced byfcnHandle
.
Example:{'y2','z'}
Data Types:cell
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, whereName
is the argument name andValue
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Example:'title','Species X versus Species Y'
specifies the axes title of the plot.
title
—Axes title
character vector|string
Axes title, specified as the comma-separated pair consisting of'title'
and character vector or string.
Example:'title','Prey versus Predator'
Data Types:char
|string
xlabel
—Label forx-axis
character vector|string
Label for thex-axis of the plot, specified as the comma-separated pair consisting of'xlabel'
and a character vector or string.
Example:'xlabel','y1'
Data Types:char
|string
ylabel
—Label fory-axis
character vector|string
Label for they-axis of the plot, specified as the comma-separated pair consisting of'ylabel'
and a character vector or string.
Example:'ylabel','y2'
Data Types:char
|string
Version History
Introduced in R2008aR2020a:Legends are statically displayed
Starting in R2020a, the figure legends are statistically displayed. TheAll Runscheckbox has been removed.
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)