Borrar filtros
Borrar filtros

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

8 visualizaciones (últimos 30 días)
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?

Respuestas (1)

Samay Sagar
Samay Sagar el 26 de Abr. de 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!

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by