Effacer les filtres
Effacer les filtres

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

16 vues (au cours des 30 derniers jours)
Pan Zhao
Pan Zhao le 12 Mai 2017
Commenté : Ben MacCallum le 21 Juin 2021
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

Réponse acceptée

Pan Zhao
Pan Zhao le 25 Mai 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 commentaires
Mounir guesbaya
Mounir guesbaya le 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 le 21 Juin 2021
I added a "Unit Delay" block on the line responsible for the algebraic loop and it solved my problem.

Connectez-vous pour commenter.

Plus de réponses (1)

Ankit Bhatnagar
Ankit Bhatnagar le 15 Mai 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 commentaire
Pan Zhao
Pan Zhao le 25 Mai 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur General Applications dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by