状态流®application programming interface (API) allows you to create or change Stateflow charts from the MATLAB®命令窗口。通过将stateFlow API命令放置在MATLAB函数或脚本中,您可以:
Automate your chart modification operations by executing several editing steps in a single command.
Eliminate repetitive chart creation steps by producing a "base" Stateflow chart that you can reuse as a template for your applications.
Produce a specialized report of your model.
状态流API由代表状态流图的图形和非图形对象组成。例如,API对象Stateflow.State
和Stateflow.Transition
represent states and transitions in a Stateflow chart. When you modify the properties of an API object or call one of its object functions, you affect the corresponding object in the Stateflow chart. When you use the Stateflow Editor to perform an operation on an object in the chart, you affect the corresponding API object.
Note
您不能使用StateFlow API执行的状态流编辑器中的任何操作。如果您通过API执行编辑操作,则撤消和Redo快速访问工具栏中的按钮被禁用。
Stateflow API objects are organized in a containment hierarchy. For example, if stateA
包含状态B
在状态流图中,然后是状态的API对象A
包含状态的API对象B
。状态流APIhierarchy follows the same rules of containment as the Stateflow object hierarchy. For example, charts can contain states, but states cannot contain charts. For more information, seeOverview of Stateflow Objects。
该图显示了状态流API中对象的层次结构。
层次结构包括四个限制级别:
根— TheSimulink.Root
object is the parent of all Stateflow API objects. It is a placeholder at the top of the Stateflow API hierarchy that distinguishes Stateflow objects from other objects in a Simulink®model. You automatically create theSimulink.Root
object when you add a Stateflow chart, a状态过渡表块,aTruth Tableblock, or aMATLAB功能块到simulink模金宝app型,或者加载包含这些块之一的模型时。
Machine- 从状态流的角度来看,Stateflow.Machine
objects are equivalent to Simulink models. AStateflow.Machine
对象包含表示状态流图的对象,状态过渡表块,Truth Table块,和MATLAB功能blocks in a model.
Chart—Stateflow.Chart
,Stateflow.StateTransitionTableChart
,Stateflow.TruthTableChart
, 和Stateflow.EMChart
objects represent Stateflow charts,状态过渡表块,Truth Table块,和MATLAB功能块分别。层次结构级别中的对象可以包含表示状态,功能,框,数据,事件,消息,过渡,连接,进入和退出端口以及注释的对象。
状态,功能和盒子- 这种层次结构包括Stateflow.State
,Stateflow.Function
, 和Stateflow.Box
分别表示状态,功能和框的对象。这些对象可以包含代表状态,功能,框,数据,事件,消息,过渡,连接,进入和出口端口以及注释的其他对象。嵌套的水平可以无限期地继续。
The hierarchy diagram shows two object types that exist outside of the containment hierarchy:
Editor—Stateflow.Editor
objects provide access to the graphical aspects of charts and state transition tables. For eachStateflow.Chart
或者Stateflow.StateTransitionTableChart
object, there is aStateflow.Editor
object that you can use to control the position, size, and magnification level of the Stateflow Editor. For more information, seeZoom in on Stateflow Chart,在状态流图上缩放, 和设置变焦因子。
剪贴板— TheStateflow.Clipboard
对象具有两个功能,复制
和pasteTo
, that use the clipboard as a staging area to implement copy-and-paste functionality in the Stateflow API. For more information, seeCopy and Paste by Grouping和Copy and Paste Array of Objects。
要使用状态流API,您首先访问Simulink.Root
object, which is the parent of all objects in the Stateflow API. You use theSimulink.Root
对象可以访问模型中的其他API对象。例如:
Create a Simulink model with an empty Stateflow chart by calling the functionsfnew
。
sfnew
使用该功能Sfroot
访问Simulink.Root
目的。
rt = sfroot;
Call the寻找
访问的功能Stateflow.Chart
对象模型中对应的图表。
ch = find(rt,'-isa','stateflow.chart');
Call theStateflow.State
function to add a state to the chart. This function returns anStateflow.State
对应于新状态的对象。
st = Stateflow.State(ch);
Display the new state in the Stateflow Editor.
查看(ST)
有关更多信息,请参阅Access Objects in Your Stateflow Chart和Create Charts by Using the Stateflow API。
APIobjects have properties that correspond to the values you set in the Stateflow Editor. For example, to use the editor to change the position of a state, you click and drag the state. With the Stateflow API, you change the position of a state by modifying the位置
property of the correspondingStateflow.State
目的:
圣置= [10 20 100 80];
APIobjects have functions that correspond to actions in the Stateflow Editor. For example, to use the editor to open the Properties dialog box for a transition, you right-click the transition and selectProperties。使用状态流API,您可以通过调用该对话框打开此对话框对话
function of the correspondingStateflow.Transition
目的:
对话(tr);
Stateflow.Box
|Stateflow.Chart
|Stateflow.Clipboard
|Stateflow.Editor
|Stateflow.EMChart
|Stateflow.Function
|Stateflow.Machine
|Stateflow.State
|Stateflow.StateTransitionTableChart
|Stateflow.Transition
|Stateflow.TruthTableChart