MATLAB: How to add a Stateflow chart in an existing Simulink model using API

apichart creationsimulinkstateflow

Consider an existing Simulink model with several subsystems connected with each other through ports and connectors. I want to know how to add Stateflow Chart within the subsystems using the API.
With the commands 'sfnew' and 'stateflow' I can only generate a new Simulink model with Stateflow Chart instead of adding a chart into an already existing model.

Best Answer

You can use the add_block function to add a Stateflow chart to an existing subsystem.
So for example, to add a Stateflow chart to a subsystem called "Subsystem" in a model called "my_model", and name that chart, "MyChart", you would use the following command:
add_block('sflib/Chart','my_model/Subsystem/MyChart')
Related Question