How do I execute a function only one time in Simulink?

96 ビュー (過去 30 日間)
Evan John
Evan John 2018 年 1 月 31 日
コメント済み: Robert Jack 2023 年 7 月 27 日
I am using an interpreted MATLAB function in simulink, to do some calculations. It then passes the results out that can be used by the rest of the model. However, it is very computationally expensive and cannot be done at every single time step. I want to run the simulation for 600 seconds with a time step of 0.1 seconds, but I only want this interpreted MATLAB function block to run every 100 seconds. Does anyone know how to do this? One approach I have been thinking about is almost like an if-statement, where the function will execute when the system time mod 100 = 0 (guarantees it will happen every 100 seconds), but I do not know how to do this in simulink. Thank you for your help!

回答 (3 件)

Jim Riggs
Jim Riggs 2019 年 7 月 29 日
This is what rate transition blocks were created for. You might want to try this approach.
Simply insert a rate transition block on the input signal to the block that you want to run at a lower rate, and set the rate inside the rate transition block. You will find this block on the signal attributes menue.
MatlabAnswers 20190729.JPG
  1 件のコメント
sajid ali
sajid ali 2020 年 11 月 29 日
thanks it was helpful

サインインしてコメントする。


Carter Nolan
Carter Nolan 2019 年 7 月 29 日
There are two ways to do that :
1 -
First : Use the command get_param('YourModel','SimulationTime')
To get the time of the simulation and then set your
if .... else .... end
fonction. (Source)
2 -
The second Method is the same idea, but done purely by Simulink, where you use a Clock and Mod function with the sampling time you want to use : (Source)
delete.jpeg

Sean de Wolski
Sean de Wolski 2018 年 1 月 31 日
編集済み: Sean de Wolski 2018 年 1 月 31 日
  1 件のコメント
Robert Jack
Robert Jack 2023 年 7 月 27 日
Page no longer exists.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by