3
votes

I have a Simulink model that includes the following subsystem.

Simulink subsystem with interpreted MATLAB function

The bm_train_adapter block will call a MATLAB function of the same name, passing all the input arguments in a single vector.

The subsystem has been given a sample time of 900 (secs), which is why all the signals are colored in red (for discrete signals).

However, in the debugger I have observed that the bm_train_adapter function gets called twice at each simulation timestep. This yields horribly wrong results since the function includes side-effects.

Why is Simulink calling my interpreted MATLAB function more than once per timestep? How can I prevent this?

2

2 Answers

1
votes

I think this is because of your solver setup. In your Configuration Parameters window, check out the Solver Options pane.

I believe the discrete and ode1 solvers will call once per timestep. ode2 will call twice per timestep, ode4 will call 4 times per timestep, etc.

This behavior is very helpful for simulating continuous dynamics, but it can be confusing when interacting with discrete elements.

1
votes

The reason was that my model had algebraic loops caused by unit delay blocks in subsystems. To solve these loops, the solver had no choice but to evaluate some blocks more than once.

The solution was to move out all unit delays from their subsystems.