Programatically create a new Stateflow chart inside an existing subsystem
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ben Wetherill
am 23 Okt. 2025
Beantwortet: Fangjun Jiang
am 23 Okt. 2025
The following concerns versions 2020b and 2024b.
I'm creating a code importer that parses XML to generate a model within simulink. The XML encodes regular interconnected logic gates, numerical comparitors, conditionals, etc arranged in subsystems. This all works fine. One subsystem contains a Stateflow chart and this is where I fall down.
I can create a new sf chart using the sfnew command, but this creates a new chart in a new window. I can't see anyway of telling it to create a chart object in a defined subsystem. I also can't see a way of even telling sfnew to create a new chart silently, without spawning a new window. I want to do all this in memory withou windows popping in and out of existance.
I have tried commands similar to the following,
>> modelName = 'flow_demo';
>> open_system(modelName);
>> subsystemPath = [modelName,'/Subsystem'];
>> add_block('built-in/Subsystem', subsystemPath);
>> subsystemHandle = get_param(subsystemPath, 'Handle');
>> chart = Stateflow.Chart(subsystemHandle);
but I get the following error message:
Error using Stateflow.Chart
No constructor 'Stateflow.Chart' with matching signature found.
Out of despiration I also tried add_block, but met with the error 'There is no block named 'Stateflow/Chart''
So how can I create a new stateflow chart silently, similar to 'add_block('built-in/Subsystem', subsystemPath);'?
After this point the APIs allow me to manipulate the the chart as I need.
Thanks.
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 23 Okt. 2025
Use below to add a new Stateflow chart block and then use Stateflow API.
add_block('sflib/Chart','MyModel/MySubSystem/MyChart')
Usually, start with below to find the handle of the Stateflow chart
ch = find(sfroot,"-isa","Stateflow.Chart")
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!