missing parameter to change fixed step size via code

17 views (last 30 days)
Hey there,
i just want to know, how the hell i can set fixed-step size programmatically.
If I'm glancing here
and here
with
so far i cannot really get a clearly parameter name to set the following value via code.
But obviously i could set it manually in the model properties tab.
So there have to be aaaannnny parameter, which is changing this 0.1 via code, but i cannot find it.
when i'm trying ...
mdl = 'blaaa';
open_system(mdl);
% load configuration:
mdlConfObj = getActiveConfigSet(mdl);
% read some parameters:
get_param(mdlConfObj,'StartTime')
get_param(mdlConfObj,'StopTime')
get_param(mdlConfObj,'fundamental sample time')
get_param(mdlConfObj,'Fixed-step size')
get_param(mdlConfObj,'fixed-step size')
get_param(mdlConfObj,'fixed step')
get_param(mdlConfObj,'step')
...and many more
% set some parameter:
set_param(mdlConfObj,'StartTime',"0")
set_param(mdlConfObj,'StopTime',"45")
set_param(mdlConfObj,'SolverType','Fixed-Step');
set_param(mdlConfObj,'fundamental sample time')
...
% setActiveConfigSet(mdl,'mdlConfObj'); % not yet
there is no way. i always get alerts like this
Property 'Fixed-step size' does not exist
Does anybody know what i have to type to get the damn 0.1 changed (via script!!!) ? This is so badly documented..
many thanks
regards

Accepted Answer

Peter O
Peter O on 4 Jul 2021
CurrentTimeStep = get_param(gcs, 'FixedStep');
set_param(gcs,'FixedStep','0.1')
gcs is a MATLAB call for "get current system".
You can extract all of the top level parameters:
get_param(gcs,'ObjectParameters')
And for block level parameters:
get_param('path-to-block','ObjectParameters')
Does that help?
  4 Comments
Peter O
Peter O on 5 Jul 2021
Bastian,
Three follow-up comments/questions:
  1. By equidistant, do you mean that you want a model output at a regular interval or fixed sampling time? For instance, you are creating a waveform and you want the position of a ball every 0.1 seconds? You aren't restricted to fixed timestep solvers and can still use a variable step solver in that case. Just set the SampleTime of the block or logger to your desired rate in its Block Parameters. This approach is also effective when you're logging a lot of data or need a really small timestep for the simulation to run but only want to collect a subset of logged data at a slower rate. It will interpolate if the step it takes exceeds the logging interval, and this is generally OK because of the way Simulink checks error in the derivatives and states as it moves along. To avoid that behavior you can set the maximum sample time to your logging rate.
  2. Parsim is most effective when you are simulating separable cases, such as looking at how results are affected by a parameter change or different input. Is that the end goal here? In general, you can't simulate the dynamic response of a single system by splitting its sample time across multiple parallel simulations because the behavior of future times rely on the state at previous time steps. If you can provide a little extra detail about the application or problem, we might find a few ways to improve the simulation speed.
  3. The sim command you're referencing is an older syntax available for compatibility, where sim accepts an argument of time points where it must return a solution (pre 2009 behavior). From the docs: "The timespan can be TFinal, [TStart TFinal], or [TStart OutputTimes TFinal]. Output times are time points returned in T, but in general, T includes additional time points."
Bass Tea
Bass Tea on 6 Jul 2021
hi hi :),
  1. yah, it was meant to be at a fixed sampling time, whatever simulation interval was. i wanted to get the results at fixed timestamps and this equidistant behavior shouldn't vary from simulation's start time til simulation's end time
  2. yah, indeed. i was sweeping a parameter and wanted to use multiple CPU cores to calculate the multiple simulations
  3. this is very interesting. i gonna try out right now. so far i did the simulation with that older ...
sim('model', 'wanted timestamps')
  • ... command. yah, you are right, this shouldn't be used in v2021 ^.^ If i can get the same behavior with that hints you mentioned, i'm totally fine with it (the bullet list at the beginning of this line is just to indent correctly)
Many thanks @Peter O for your effort. i really appreciate it. =) !
Take Care

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!