How can I view/edit the data of a Stateflow Chart in a Simulink model using command line if the Simulink chart is derived from a custom library in MATLAB 8.0(R2012b)?

2 views (last 30 days)
I have a Stateflow chart in my Simulink model which is linked to a library. I would like to access/edit the data in the Stateflow chart using command line without breaking the link to the library.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Jun 2013
You can combine the basic Simulink API with the Stateflow API to achieve this from command line. Since the Stateflow chart in the model is linked to a library, in order to be able to make any changes in the data in the chart, you need to disable the link between the block and the library first. You can disable the link using command line and then enable the link and push the changes made in the chart to the library. However, if you just wish to view the data in the Stateflow chart, this can be done without breaking the link. The following two scripts show how both of these tasks can be achived from command line:
The Simulink model 'testapi.slx' and library 'test1.slx' are attached with the solution.
%%Editing Data in a Stateflow chart and pushing the changes to the library block
% Find the Chart in the Simulink Model
cellChart=find_system('testapi','MaskType','Stateflow','Name','myChart');
% Disable the link
set_param(cellChart{1},'LinkStatus','inactive');
% Using stateflow API now to get the stateflow chart data.
rt=sfroot;
m = rt.find('-isa', 'Simulink.BlockDiagram', '-and', ...
'Name', 'testapi');
ch = m.find('-isa','Stateflow.Chart','-and',...
'Name','myChart');
chData = ch.find('-isa', 'Stateflow.Data','-and',...
'Name','u');
% Now, for example if you want to change the update method of a variable, you can do the following:
set(chData(1),'UpdateMethod','Continuous')
% You can now push the changes back to the library block.
set_param(cellChart{1},'LinkStatus','propagate');
%%Viewing the data in a Stateflow chart which is linked to a library.
% Find the Chart in the Simulink Model
hChart=find_system('testapi','MaskType','Stateflow','Name','myChart');
% Find the full path to the library block to which the chart is linked to
libBlock=get_param(hChart,'ReferenceBlock');
% Get the handle to Libary block
hLib=get(get_param(libBlock{1},'Handle'));
% Creating a root stateflow object
rt = sfroot;
% Find the library model using stateflow API
m = rt.find('-isa','Simulink.BlockDiagram','-and',...
'Name',hLib.Parent);
% Find the library block
ch = m.find('-isa','Stateflow.Chart','-and',...
'Name',hLib.Name);
% Assigning all data contained in the library block to 'chData'
chData = ch.find('-isa', 'Stateflow.Data');

More Answers (0)

Categories

Find more on Stateflow in Help Center and File Exchange

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!