Variable gets cleared after each simulation step with simulink

1 回表示 (過去 30 日間)
Friedrich
Friedrich 2024 年 9 月 16 日
コメント済み: Malay Agarwal 2024 年 9 月 19 日
Hello all,
I am using a System Object (SO) in combination with Simulink to simulate some stuff. Within that SO multiple objects of normal Matlab classes are instantiated in the setupImpl method. From one stepImpl to the next it seems that Matlab/Simulink clears/re-initializes the properties of those Matlab objects which in return costs time. How can I prevent this from happening? I want the memory of the Matlab Objects to be untouched because the size of their properties is large and don't change over time. I thought of using persistent variables but I fail in defining persistent properties. Is that possible and if so, how?
Any hint is highly appreciated!
  1 件のコメント
Stefan
Stefan 2024 年 9 月 16 日
Dear Friedrich,
thanks for your request - we will be in touch shortly.
Thanks and best,
Stefan

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

回答 (1 件)

Malay Agarwal
Malay Agarwal 2024 年 9 月 17 日
編集済み: Malay Agarwal 2024 年 9 月 17 日
According to the documentation of the setupImpl method, you need to define properties as private properties to avoid them from being recalculated on each call to stepImpl (https://www.mathworks.com/help/releases/R2021b/matlab/ref/matlab.system.setupimpl.html#:~:text=class%20definition%20file.-,Use%20setupImpl,-to%20set%20private)
"Use setupImpl to set private properties so they do not need to be calculated each time stepImpl method is called."
Please make sure that all your instances are defined as private properties your code.
Refer to the following resource for more information on how to use the setupImpl method: https://www.mathworks.com/help/releases/R2021b/matlab/ref/matlab.system.setupimpl.html
Hope this helps!
  3 件のコメント
Friedrich
Friedrich 2024 年 9 月 17 日
I'll try to come up with a minimal example as soon as possible. I guess that would help all of us.
Malay Agarwal
Malay Agarwal 2024 年 9 月 19 日
Yes, I think that would be very helpful!

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

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by