How to find Stateflow chart using API's

Hello All,
I have simulink model with Subsystem. My subssystem are linked with Library and these library links are resolved. Inside subsystem, I have stateflow chart. I want to find stateflow chart using m-scripts.
sflow=sfroot;
model = sflow.find('-isa', 'Simulink.BlockDiagram','-and','Name','libraryIncluded');
chartArray = model.find('-isa','Stateflow.Chart');
here chartArray = model.find('-isa','Stateflow.Chart'); does not returns statflow charts from library links. How can I get all charts from linked libraries?
PS: Please find Library file and simulink model from attachments

 採用された回答

Fangjun Jiang
Fangjun Jiang 2015 年 8 月 3 日

2 投票

I had a similar need but couldn't find a way. It was confirmed by the Mathworks tech support that there is no direct way to find the Stateflow chart objects inside a linked library block in a model. I ended up writing the following code. It was verified in many models, including some models with nested library links.
% Updating the model is needed to make sure libraries, if any, are loaded
% There might be error updating the model, but the error are non-critical
% for this operation
try
fprintf(1,'Need to update the model to load all libraries.\n');
set_param(Model,'SimulationCommand','Update');
catch %#ok<CTCH>
fprintf(1,'There are errors updating the model. Ignore ...');
end
ChartRoots=libinfo(Model);
ChartRoots=[{Model},{ChartRoots.Library}];
sfrt=sfroot;
ChartObj=sfrt.find('-isa','Stateflow.Chart');
Index=ismember(bdroot(get(ChartObj,'Path')),ChartRoots);
ChartObj=ChartObj(Index);

4 件のコメント

N/A
N/A 2015 年 8 月 3 日
Hello Fangjun,
Thanks for the answer..I wrote following code.
sflow=sfroot;
chartArray = sflow.find('-isa','Stateflow.Chart');
%find all subsystems including charts from subsystem in current model
SubSystems = find_system(mdl, 'FollowLinks', 'on', 'LookUnderMasks','on', 'BlockType', 'SubSystem');
SubSystemsChartNames = {};
for y=1: length(SubSystems)
subSystemPath = SubSystems{y};
nlChar = max(strfind(subSystemPath,'/'));
SubSystemsChartNames{end+1} = subSystemPath(nlChar+1:end);%get subsystem names
end
for m = 1:length(chartArray)
if (ismember(chartArray(m).Name,SubSystemsChartNames) || strcmp(mdl,bdroot(chartArray(m).Path)))
currentChart = chartArray(m);
%do chart data processing
end
end
could you please check and let me know whether it is good practice or not?
I will check your code as well..
Fangjun Jiang
Fangjun Jiang 2015 年 8 月 6 日
編集済み: Fangjun Jiang 2015 年 8 月 6 日
To get SubSystemsChartNames, it can be simplified
SubSystems = find_system(mdl,'FindAll','On', 'FollowLinks', 'on', 'LookUnderMasks','on', 'BlockType', 'SubSystem');
SubSystemsChartNames=get(SubSystems,'Name');
You are already aware that matching the root of the chart with the model name doesn't include the charts inside a linked subsystem. Adding your second logic by matching chart name with any of the SubSystemsChartNames is not robust. You could have many models open in the memory. The chart names from other open models could accidentally match SubSystemsChartNames thus be incorrectly included.
My code matches the root of the chart with your model name and any library names used by that model. It is accurate, no more, no less.
Sean de Wolski
Sean de Wolski 2015 年 8 月 6 日

Welcome back Fangjun!

N/A
N/A 2015 年 8 月 7 日
Thank you Fangjun..

サインインしてコメントする。

その他の回答 (1 件)

Philipp
Philipp 2025 年 3 月 12 日

1 投票

You can configure a finder from slreportgen to find Stateflow charts in linked / resolved libraries:
% Create the finder for the model / library "mdlName"
% by using this finder instead of the stateflow search api we can follow links
sfFinder = slreportgen.finder.ChartDiagramFinder(mdlName);
% configure following links
sfFinder.IncludeSimulinkLibraryLinks = 1; % default is true, just as demonstration
sfFinder.IncludeUserLibraryLinks = 1; % default is true
% Find the Stateflow charts in model / its libraries
sfResults = find(sfFinder);
stateflowChartsArray = [sfResults.Object]

カテゴリ

ヘルプ センター および File ExchangeDecision Logic についてさらに検索

質問済み:

N/A
2015 年 7 月 28 日

コメント済み:

2025 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by