How to set the number of sampling points when simulating using Simbiology APP

10 次查看(过去 30 天)
How to set the number of sampling points when simulating using Simbiology APP? e.g., if 50 or 100 sampling points was to be simulated from 0 to 120 hours, how to set them respectively?

采纳的回答

Jeremy Huard
Jeremy Huard 2024-1-15
编辑:Jeremy Huard 2024-1-15
In the Model Analyzer App you can define the output times for all simulations of your model in its Simulation Settings :
You could for example type 0:0.5:32 for SimBiology to return simulation results at 0,0.5,1,1.5,...,31.5,32 hours.
This setting will apply to all simulations run with this model.
Starting R2022b you can define output times for single simulation programs instead. In a simulation section (included in a single simulation program or scan for example), you can exclude solver time points and only include specified output times instead:
Best regards,
Jérémy

更多回答(2 个)

Hassaan
Hassaan 2024-1-15
  1. Open your model in the SimBiology app.
  2. Click on the 'Simulation' tab in the toolstrip at the top.
  3. In the 'Simulation Settings' section, you will find an option to specify the 'Time (s)' or 'Time (hr)', depending on the units you are using.
  4. To specify the time points, you can manually enter a vector of times at which SimBiology will perform the simulation. For example:
  • For 50 sampling points, you would create a vector that goes from 0 to 120 hours with 50 equally spaced points. You can use the linspace function in MATLAB for this:
time_vector = linspace(0, 120, 50);
For 100 sampling points, simply change the last argument of linspace to 100:
time_vector = linspace(0, 120, 100);
  1. Enter the generated time vector into the 'Time' field in the simulation settings.
Please note that the exact steps may vary slightly depending on the version of MATLAB and the SimBiology app you are using. If you are setting this from a script or the command line, you would use the simbiology command to simulate the model, passing in the time_vector as one of the arguments.
If you're running simulations from the command line or a script, you can use the sbiosimulate function. For example:
% Create a model (or load your existing model)
m = sbiomodel('my_model');
% Add components to your model (reactions, species, etc.)
% Set up the config set for the simulation
cs = getconfigset(m, 'active');
set(cs, 'SolverType', 'ode15s'); % for example, setting the solver
set(cs, 'StopTime', 120); % simulation time in hours
% Set time vector for 50 sampling points
time_vector_50 = linspace(0, 120, 50);
% Simulate the model
[~, ~, output_50] = sbiosimulate(m, cs, time_vector_50);
% Set time vector for 100 sampling points
time_vector_100 = linspace(0, 120, 100);
% Simulate the model
[~, ~, output_100] = sbiosimulate(m, cs, time_vector_100);
In the above example, output_50 and output_100 will contain the simulation results for 50 and 100 sampling points
respectively. Each row in the output corresponds to a time point, and each column corresponds to a model component (e.g., species concentration).
It's important to set the StopTime property of the config set to match the last point in your time vector, and to make sure the solver type is appropriate for your model.
---------------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Pratyush
Pratyush 2024-1-15
编辑:Pratyush 2024-1-15
Hi,
I understand that you want to simulate a model created with SimBiology for a given number of sampling points.
You can use the 'sbiosimulate' function in MATLAB to simulate a model created with SimBiology and specify the number of sampling points. To set up a simulation with a specific number of points, you would typically use the 'sbiotimecourse' function to create a configuration set with the desired simulation time and number of points, and then pass this configuration to 'sbiosimulate'.
Here is an example of how you would set up a simulation with 50 and 100 sampling points from 0 to 120 hours:
% Load your model (replace 'mymodel' with the actual model variable)
model = sbmlimport('mymodel.sbml');
% Define simulation time
startTime = 0; % Start time in hours
stopTime = 120; % Stop time in hours
% For 50 sampling points
numPoints50 = 50;
configset50 = getconfigset(model);
set(configset50, 'SolverType', 'ode15s'); % Choose an appropriate solver
set(configset50, 'StopTime', stopTime);
set(configset50, 'TimeUnits', 'hour');
set(configset50, 'OutputTimes', linspace(startTime, stopTime, numPoints50));
simData50 = sbiosimulate(model, configset50);
% For 100 sampling points
numPoints100 = 100;
configset100 = getconfigset(model);
set(configset100, 'SolverType', 'ode15s'); % Choose an appropriate solver
set(configset100, 'StopTime', stopTime);
set(configset100, 'TimeUnits', 'hour');
set(configset100, 'OutputTimes', linspace(startTime, stopTime, numPoints100));
simData100 = sbiosimulate(model, configset100);
Here 'linspace' is used to generate a vector of linearly spaced time points between the start and stop times. The number of elements in this vector corresponds to the number of sampling points you want.

社区

更多回答在  SimBiology Community

类别

Help CenterFile Exchange 中查找有关 Scan Parameter Ranges 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by