Programatically create a new Stateflow chart inside an existing subsystem
조회 수: 25 (최근 30일)
이전 댓글 표시
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
채택된 답변
Fangjun Jiang
2025년 10월 23일 11:54
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!