Stateflow | ![]() ![]() |
Creating a MATLAB Script of API Commands
In the Quick Start for the Stateflow API section, you created and saved a new model through a series of Stateflow API commands. You can include the same API commands in the following MATLAB script, which allows you to quickly recreate the same model with a single command (>> makeMyModel
).
function makeMyModel sfnew; rt = sfroot; m = rt.find('-isa','Stateflow.Machine'); chart = m.find('-isa', 'Stateflow.Chart'); sA = Stateflow.State(chart); sA.Name = 'A'; sA.Position = [45 45 300 150]; sA1 = Stateflow.State(chart); sA1.Name = 'A1'; sA1.Position = [80 80 90 80]; sA2 = Stateflow.State(chart); sA2.Name = 'A2'; sA2.Position = [220 80 90 80]; tA1A2 = Stateflow.Transition(chart); tA1A2.Source = sA1; tA1A2.Destination = sA2; tA1A2.SourceOClock = 3.; tA1A2.DestinationOClock = 9.; sA11 = Stateflow.State(chart); sA11.Name = 'A11'; sA11.Position = [110 110 35 35]; tA1A11 = Stateflow.Transition(chart); tA1A11.Source = sA1; tA1A11.Destination = sA11; tA1A11.SourceOClock = 1.; tA1A11.DestinationOClock = 1.; tA1A2.LabelString = 'E1'; tA1A11.LabelString = 'E2'; pos = tA1A2.LabelPosition; pos(1) = pos(1)+15; tA1A2.LabelPosition = pos; dtA = Stateflow.Transition(chart) dtA.Destination = sA dtA.DestinationOClock = 0 xsource = sA.Position(1)+sA.Position(3)/2-10 ysource = sA.Position(2)-20 dtA.SourceEndPoint = [xsource ysource] dtA1 = Stateflow.Transition(chart) dtA1.Destination = sA1 dtA1.DestinationOClock = 0 xsource = sA1.Position(1)+sA1.Position(3)/2-10 ysource = sA1.Position(2)-20 dtA1.SourceEndPoint = [xsource ysource]
![]() | Making Supertransitions | API Properties and Methods by Use | ![]() |