Can you search for Stateflow objects in only a single model using sfroot?

6 次查看(过去 30 天)
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?

回答(1 个)

Samay Sagar
Samay Sagar 2024-4-26
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!

类别

Help CenterFile Exchange 中查找有关 Stateflow Programmatic Interface 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by