- https://www.mathworks.com/help/stateflow/ug/adding-data.html
- https://www.mathworks.com/help/stateflow/ug/access-data-store-memory-from-a-chart.html
Is it possible to declare a persistent variable in a Stateflow subchart?
11 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!