Can you search for Stateflow objects in only a single model using sfroot?
4 views (last 30 days)
Show older comments
I am trying to use the Stateflow API to access several Stateflow charts in a Simulink model.
Using the following code
sfCharts = find(sfroot,'-isa','Stateflow.Chart');
I can find all Stateflow charts, but only for all models in sfroot. Is there any way to limit this search to a specific Simulink model?
I know I can use the Simulink API, or close all other Simulink models so they are not searched, but these options are not very efficient in my use case.
Is there anyway to limit the scope of sfroot.find to a certain Simulink model?
0 Comments
Answers (1)
Samay Sagar
on 26 Apr 2024
Using the “find” function with “sfroot” does not directly limit its search to a specific Simulink model when multiple models are open because it operates at the level of the Stateflow API, providing access to all Stateflow objects in the MATLAB environment. To specifically find Stateflow charts within a particular model, a workaround can be employed to first identify the Stateflow machine associated with that model and then search within that machine.
Here is how you can implement this workaround:
modelName = "modelName";
load_system(modelName);
sfMachine = find(sfroot,"-isa","Stateflow.Machine",'-and','Name',modelName);
if ~isempty(sfMachine)
chartsInTargetModel = sfMachine.find('-isa', 'Stateflow.Chart');
disp(chartsInTargetModel);
else
disp('No Stateflow machine found for the specified model.');
end
Hope this helps!
0 Comments
See Also
Categories
Find more on Complex Logic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!