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

조회 수: 11 (최근 30일)
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

채택된 답변

Pan Zhao
Pan Zhao 2017년 5월 25일
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
Mounir guesbaya
Mounir guesbaya 2019년 10월 24일
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 2021년 6월 21일
I added a "Unit Delay" block on the line responsible for the algebraic loop and it solved my problem.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ankit Bhatnagar
Ankit Bhatnagar 2017년 5월 15일
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
Pan Zhao
Pan Zhao 2017년 5월 25일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by