Logging Active States/Data during Simulation

2 views (last 30 days)
I am trying to simulate a Simulink Model containing Statecharts using external inputs set using a time/data structure. I open the model with the following parameters set
set_param(model,...
'RecordCoverage','on',...
'CovMetricSettings','dcmtw',...
'CovSaveCumulativeToWorkspaceVar','on',...
'CovHtmlReporting','off',...
'LoadExternalInput','on',...
'ExternalInput','InputStruct',...
'OutputSaveName','OutputStruct',...
'SaveState','on',...
'SaveFormat','Structure',...
'SaveTime','on',...
'SaveOutput','on',...
'LimitDataPoints','off',...
'Decimation','1');
I am using an Structure containing time and the signal values into the sim command
sim(model,max(InputStruct.time),[],InputStruct);
I wish to store the Frame by Frame detail Active States/Transitions. In other words for a particular element of the Time Structure InputStruct.time I need Matlab to log which are the "Active States" inside the Statechart. Similar to what is shown in the Debugger Window.
I was also hoping if this information can be stored during simulation so that I need not post process the logged data after simulation is complete. I shall be using the frame by frame data to write into a structured CSV file in form of Comments containing the State Details with a row followed by the signal data where the input and output are in respective column pertaining to the signal values in the frame.

Accepted Answer

TAB
TAB on 28 Mar 2012
Below is the way to log the state informations-
1. Right click on stateflow chart block and select Log chart signals.
2. Goto to Simulation -> Configuration Parameters -> Data Import/Export & choose your log variable (default logsout), choose log formate as Structure with time.
3. Run the Simulation
After completion of simulation, log variable will be created in base workspace having the state informations for each sample time.
[EDITED 29-Mar-2012]
%Get model handle
h=get_param('YourModel','handle');
%Get model object
ob=get_param(h,'object');
%Find Stateflow charts in model
sfchart=ob.find('-isa','Stateflow.Chart');
%Find the states in this stateflow chart
sfStates=sfchart.find('-isa','Stateflow.State');
%Enable logging for all states
for x=1:length(sfStates)
sfStates(x).LoggingInfo.DataLogging = 1;
end
%Set the Global logging options (Which are in the Configuration
%parameter dialog box
set_param(h,'SignalLogging','on');
set_param(h,'SignalLoggingName','VariableName');
set_param(h,'SaveFormat','StructureWithTime');
  2 Comments
Shouvik Das
Shouvik Das on 28 Mar 2012
1. The Chart Signals need to be selected one by one in the GUI. I have nearly 450 states in my Statechart. Is there a way to do it using Scripts
2. To log data as Structure with Time I updated the Model parameter to
'SaveFormat','StructureWithTime',...
It would be of great help of you could direct me to it.
TAB
TAB on 29 Mar 2012
Find the states in the chart and set the "LoggingInfo.DataLogging" property of states to 1 to enable the logging.
See edited part of this answer.
Also See http://www.mathworks.com/help/toolbox/stateflow/ug/bsy2b2_.html#brgliqp

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!