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

조회 수: 11 (최근 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 CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by