How many times does a Matlab Function in Simulink run in one time step

11 views (last 30 days)
Hello,
I have a Matlab Function in a Simulink model. Because the Matlab Funtion is time-confusing, I just want it to run one time in a step. But it seems to run multiple (>5) times in a step. I was wondering whether the number of times a Matlab function runs in a step depends on the solver (ode1,ode4, etc) selected. Can anyone provide some insights into this question? Thank you.
Regards Pan

Accepted Answer

Pan Zhao
Pan Zhao on 25 May 2017
After struggling for one day, I found two main causes for my problem. The first one is that there was an algebraic loop in my model due to a missing setting in a S function, which made Simulink run the model MULTIPLE times in ONE time step to solve the algebraic loop. The second one is that the [Update Method] of my Matlab Function was set to be [inherited]. The problem disappeared after (1) removing the algebraic loop and (2) changing the [Update Method] to [discrete] and setting the [Sample Time] equal to the (fixed) step size of the model.
Hope this may help people who confront similar problems.
  3 Comments
Mounir guesbaya
Mounir guesbaya on 24 Oct 2019
Dear Pan Zhao,
I have found how i can change the [update method] to be [discret], but it still run the function multiple times in one sample time because of the ODE and i can get red of it because it is the solver of my non-linear model.. so, is there any other solution for this problem ??
Thank you
Ben MacCallum
Ben MacCallum on 21 Jun 2021
I added a "Unit Delay" block on the line responsible for the algebraic loop and it solved my problem.

Sign in to comment.

More Answers (1)

Ankit Bhatnagar
Ankit Bhatnagar on 15 May 2017
Hi,
There are ways to start the block after a particular major step time like using a Clock block from Simulink/Sources and using simulation time feature of a block but currently not possible to execute a block as an independent task in Simulink.
Please refer this MATLAB Answers post for further details:
  • https://www.mathworks.com/matlabcentral/answers/262892-how-do-i-make-a-simulink-embedded-function-run-independent-of-the-time-step-of-the-model
  1 Comment
Pan Zhao
Pan Zhao on 25 May 2017
Hi Ankit,
Thanks very much for your reply. I am sorry for my late response. Actually, I just want my Matlab Function to run once in a time step of the model, not asking it to run independent of the time step of the whole model. After struggling for a while, I found the problem with my model and the solution, which I will explain next in a separate answer to make them more noticeable to others.
Regards Pan

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!