MATLAB Answers

## Plot StateData at a certain time point in Simbiology

Asked by Göran Dahl

### Göran Dahl (view profile)

on 14 Feb 2019
Latest activity Commented on by Sietse Braakman

### Sietse Braakman (view profile)

on 14 Feb 2019
How can I plot StatData at a certain time point for a parameter when I peform a parameter scan in SimBiology?
I simulate how the concentration of a target (Ttot) in a cell (compartment Cell) changes over time as an effect of varying an inhibitor concentration. In the properties - data to plot tab of the scan graph window I only know how to plot the max or min values of the parameter, example:
[time, stateData] = selectbyname(simdata, 'Cell.Ttot');
out = min(stateData);
In the example above this plots the min value wherever it occurs throughout the simulation time course. I would like to be able to plot a snapshot of the concentration of Ttot at a certain time point like:
[time, stateData] = selectbyname(simdata, 'Cell.Ttot');
out = "t=x"(stateData);
Is there an expression that I could use for this? If not how would I go about to do the things I want?
I am not very adapt at using text commands for MatLab and would prefer a solution which I can use in the SimBiology module itself.
Thanks in advance

#### 0 Comments

Sign in to comment.

### Communities

More Answers in the  SimBiology Community

## 1 Answer

Answer by Jeremy Huard

### Jeremy Huard (view profile)

on 14 Feb 2019

Dear Göran,
indeed, you can achieve this by modifying the piece of code contained in the scan plot.
Let's say that you want to plot the final value of Ttot. In this case your code would be:
[time, stateData] = selectbyname(simdata, 'Cell.Ttot');
out = stateData(end);
Now, in the more general case where you wish to plot its value at any given time point you will have to consider two things. Let's first define t as the time point you are interested in.
1. SimBiology records simulation data at times chosen by the ODE solver according to solver options like tolerances, maxstep, etc... To make sure that data is recorded at time = t, you can specific output times that will include t. For example, if you want to simulate your model for 72 hours and plot Ttot at t=48 hours, you can first open the Simulation Settings in your scan task and then give the following code in OutputTimes in the Simulation settings:
0:1:72
Press enter and you will a list that includes time points between 0 and 72 hours with an interval of 1 hour, which includes 48 hours.  Note: Please note that in that case, the StopTime defined in the default simulation settings as well as in any task will be ignored and replaced by the last time point in the OutputTimes list. Also the live plot in that task will display the simulation results at those time points. In cases where the interval is chosen too large, some dynamics might not be recorded and displayed in the Live Plot, although they might have been captured correctly by the solver.
2. If your model contains dosing schedules and/or events that are triggered at time=t, your simulation data might include multiple data points at this time point. In this case you will need to know whether you wish to plot Ttot before or after that event.
For simplicity let's assume that there is no event/dose at time=t. In that case your code will be the following:
[time, stateData] = selectbyname(simdata, 'Cell.Ttot');
out = stateData(time==48);
This should produce the results you are looking for.
On a separate note since you mentioned that you are not very comfortable with using MATLAB command, I can highly recommend the free MATLAB OnRamp course. It is a 2 hour interactive course in the browser to learn the basics of the MATLAB programming language and get familiar with MATLAB in general. There are also more comprehensive trainings both online or onsite.
I hope this helps.
Best,
Jérémy

Sietse Braakman

### Sietse Braakman (view profile)

on 14 Feb 2019
An alternative solution is to resample your data. Like Jérémy explained, you will have to change the code you mentioned in your question.
Instead of defining output times in your simulation settings you can resample your simdata object. This resampling is a form of interpolation you can do between the timesteps that your solver takes (see explanation above). If I want the scan plot to display the concentration of Target in the Plasma (Plasma.Target) at time 10, you can try this:
outputTime = 10
newdata = resample(simdata,outputTime);
[time, stateData] = selectbyname(newdata, 'Plasma.Target');
out = stateData;
More on the resample function here: https://www.mathworks.com/help/simbio/ref/resample.html

Sign in to comment.