How to find Stateflow chart using API's

21 visualizaciones (últimos 30 días)
N/A
N/A el 28 de Jul. de 2015
Comentada: Fangjun Jiang el 12 de Mzo. de 2025
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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 3 de Ag. de 2015
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 comentarios
Sean de Wolski
Sean de Wolski el 6 de Ag. de 2015

Welcome back Fangjun!

N/A
N/A el 7 de Ag. de 2015
Thank you Fangjun..

Iniciar sesión para comentar.

Más respuestas (1)

Philipp
Philipp el 12 de Mzo. de 2025
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]

Categorías

Más información sobre Decision Logic en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by