MATLAB: Is there a function in Stateflow to determine how a particular “Data Store Memory” data object is being used by a Stateflow chart

datamemorystateflowstore

I want to be able to determine programmatically how a Stateflow chart is using a "Data Store Memory" data object that is defined in the chart. For example, I want to determine if the Stateflow chart is writing to the memory, reading from the memory, or both.

Best Answer

The ability to determine how a particular "Data Store Memory" data object is used in a Stateflow chart is not available in Stateflow.
To work around this issue, you can write your own MATLAB file function that uses the Stateflow API to obtain the expressions in a transition, state, or other chart object that indicate how the "Data Store Memory" is being used. As an example, you might use the following commands in the Stateflow API to access expressions in a transition and state:
rt = sfroot;
m = rt.find('-isa', 'Simulink.BlockDiagram', '-and', 'Name','myModel');
chart = m.find('-isa','Stateflow.Chart','-and','Name','mychart');
trans = find(chart, '-isa','Stateflow.Transition'); %Get all transitions
states = find(chart, '-isa','Stateflow.State'); %Get all states
transString = trans(1).LabelString; %Get the expressions in the first transition
statesString = states(1).LabelString; %Get the expressions in the first state
One way to determine if the "Data Store Memory" data object is being read from or written to is to see if it is on the right or left side of an "=" sign. You can determine this by parsing the transString and statesString strings. You can also use the STRFIND command to get the location of the "Data Store Memory" variable and the "=" sign in the expressions contained in transString and statesString strings.