主要内容

Overview of theStateflowAPI

状态流®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.StateStateflow.Transitionrepresent 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快速访问工具栏中的按钮被禁用。

层次结构StateflowAPIObjects

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中对象的层次结构。

图显示了API对象层次结构的四个级别。

层次结构包括四个限制级别:

  • — TheSimulink.Rootobject 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.Rootobject when you add a Stateflow chart, a状态过渡表块,aTruth Tableblock, or aMATLAB功能块到simulink模金宝app型,或者加载包含这些块之一的模型时。

  • Machine- 从状态流的角度来看,Stateflow.Machineobjects are equivalent to Simulink models. AStateflow.Machine对象包含表示状态流图的对象,状态过渡表块,Truth Table块,和MATLAB功能blocks in a model.

  • ChartStateflow.Chart,Stateflow.StateTransitionTableChart,Stateflow.TruthTableChart, 和Stateflow.EMChartobjects 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:

AccessStateflowAPIObjects

要使用状态流API,您首先访问Simulink.Rootobject, which is the parent of all objects in the Stateflow API. You use theSimulink.Root对象可以访问模型中的其他API对象。例如:

  1. Create a Simulink model with an empty Stateflow chart by calling the functionsfnew

    sfnew

  2. 使用该功能Sfroot访问Simulink.Root目的。

    rt = sfroot;

  3. Call the寻找访问的功能Stateflow.Chart对象模型中对应的图表。

    ch = find(rt,'-isa','stateflow.chart');

  4. Call theStateflow.Statefunction to add a state to the chart. This function returns anStateflow.State对应于新状态的对象。

    st = Stateflow.State(ch);

  5. Display the new state in the Stateflow Editor.

    查看(ST)

有关更多信息,请参阅Access Objects in Your Stateflow ChartCreate Charts by Using the Stateflow API

修改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];
有关更多信息,请参阅Modify Properties and Call Functions of Stateflow Objects

调用API对象功能

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);
有关更多信息,请参阅Modify Properties and Call Functions of Stateflow Objects

See Also

Functions

Objects

相关话题