Search code examples
matlabmodelsimulationsimulink

How to change the sampling time for all of the model blocks in Simulink?


I have a model and I need to change the sample time of each block that I currently have in my Simulink model.

The problem is that I have so many blocks that make changing this parameter for each individual one cumbersome. Is there a means to change it for a group of blocks?

One more thing, what is the default sample time indicated by "-1"?


Solution

  • This can be done quite easily. In general it is a good practise to be aware of the simulation time, simulation steps and solver you are using in simulink simulations, as sometimes the simulation can go wrong just because of the solver, or because of the simulation step size.

    To change all this parameters (and the step size, what I assume is your "sampling time") you need to go to the Solve Pane that looks like this:

    enter image description here

    You can see in there how "Max step size" and "min step size" are there, set to auto. This two exist because some odes (as ode45 in this case) use variable step size, but if you want fixed step size you can change the solver to ode1 or ode3 for example.

    About that -1 thing... You should not change each blocks sample rate unless you really meant to. When do yo want to do this? In general when you want the sample rate of THAT specific block to be smaller than the rest. So if you have a simulation that is running the whole system at 1e-2 sample rate, and you have an specific block thatneeds to run just every second, then you change the sample rate. Else the default is -1, which means the same sample rate that you have set up in the Solve Pane.

    So:

    • ALWAYS be aware of whats going on in the Solve Pane
    • Dont change those "-1" unless you really meant to