Is it possible to declare a persistent variable in a Stateflow subchart?

8 ビュー (過去 30 日間)
Marcos Barcelo
Marcos Barcelo 2022 年 8 月 3 日
回答済み: Ayush 2023 年 9 月 13 日
Hi!
I'm using a Stateflow chart to generate some code (C action language). I would like to declare a subchart variable as persistent (or static), so the value is remembered the next time the subchart is executed.
A solution is to attach this variable to one of the parent states, but then this variable is visible to all the subcharts, which is not ideal.
Another solution is to create an embedded Matlab function with persistent variables on it, but this is too cumbersome, since I would need to read all the variables in the beginning and write them before leaving the state.
Is there a simpler way to achieve this?

回答 (1 件)

Ayush
Ayush 2023 年 9 月 13 日
Hi Marcos,
I understand that you want to declare a persistent variable in a Stateflow sub chart.
It can be achieved by using the “Data Store Memory” block in Simulink which enables the use of a persistent variable by binding the scope of your Stateflow data object to an independent memory region.
Please refer to the below documentations to know more about the workflow involved in integrating a “Data Store Memory” block to your Stateflow Chart:
I hope it helps,
Regards,
Ayush Misra

カテゴリ

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