필터 지우기
필터 지우기

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

조회 수: 8 (최근 30일)
MrPowerElectronics
MrPowerElectronics 2021년 11월 30일
답변: Samay Sagar 2024년 4월 26일
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에서 Complex Logic에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by