How do I get the minor time in a MATLAB s-function?

2 ビュー (過去 30 日間)
manav .
manav . 2011 年 5 月 26 日
回答済み: tianyuan wang 2023 年 3 月 9 日
Inside a Level-2 Matlab S-function, block.CurrentTime gives the value of the major time. How can we get the value of the minor time?

採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 5 月 26 日
Actually, block.CurrentTime gives the value of the current time-step in the simulation (could be either major or minor). The block outputs and derivatives (and potentially, zero-crossings) methods are run in minor time-steps. So if you are querying block.CurrentTime in one of these functions, you should simply have to check block.IsMajorTimeStep to verify if you're in a major/minor time-step.
  1 件のコメント
Rik
Rik 2020 年 8 月 13 日
Comment posted as flag by Abbott Von:
Simulink level-2 S_function获取当前仿真时间

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

その他の回答 (2 件)

Guy Rouleau
Guy Rouleau 2011 年 5 月 27 日
I recommend looking at this submission:
It contains a level-2 MATLAB s-function which reads and separate values from major and minor steps.
I use the files in this submission often to better understand continuous solver behavior. Just for my curiosity, can you provide more details on why you want to access minor time steps data?
  2 件のコメント
manav .
manav . 2011 年 5 月 30 日
My model has an S-function block containing transient FEM code, which requires time step between two consecutive calls to determine its output. But as the system output becomes unstable after sometime (before unstability it gives proper output), time step seemed to be culprit to me, though incorrectly as I know now.
But thanks as I have better understanding of major and minor time step now.
trantoan
trantoan 2018 年 4 月 20 日
Hi manav, I wonder if you could share your solution strategy. At the present, I have a similar issue. Hope to hear your recommendation. Best, Toan

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


tianyuan wang
tianyuan wang 2023 年 3 月 9 日
I encountered a similar problem.
If I choose the ode4 solver, does the model loop four times in one time step?
Another question is, if I use S-function in my model and call S-function once in a time step, how does ode4 extrapolate the results of S-functions? Does the result of the S-function have to be a function of time t? Or Simulink automatically extrapolate based on the value of S-function?

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by