Main Content

Stateflow.EMFunction

MATLAB function in chart, state, box, or function

    Description

    Use Stateflow.EMFunction objects to create MATLAB® functions for coding algorithms that are more easily expressed by using MATLAB code instead of the graphical Stateflow® constructs. Typical applications include:

    • Matrix-oriented calculations

    • Data analysis and visualization

    You can call a MATLAB function in the actions of states and transitions. For more information, see Reuse MATLAB Code by Defining MATLAB Functions.

    Creation

    Description

    example

    function = Stateflow.EMFunction(parent) creates a Stateflow.EMFunction object in a parent chart, state, box, or function.

    Input Arguments

    expand all

    Parent for the new MATLAB function, specified as a Stateflow API object of one of these types:

    Properties

    expand all

    Stateflow API objects have properties that correspond to the values you set in the Stateflow Editor. To access or modify a property, use dot notation. To access or modify multiple properties for multiple API objects, use the get and set functions, respectively. For more information, see Modify Properties and Call Functions of Stateflow Objects.

    Content

    Name of the MATLAB function, specified as a character vector.

    Label for the MATLAB function, specified as a character vector.

    Code for the MATLAB function, specified as a character vector. To enter multiple lines of code, you can:

    • Call the MATLAB function sprintf and use the escape sequence \n to insert newline characters:

      str = sprintf('function y=f(x)\ny=x+1;\nend');
      function.Script = str;
    • Enter a concatenated text expression that uses the integer 10 as the ASCII equivalent of a newline character:

      str = ['function y=f(x)',10, ...
          'y=x+1;',10, ...
          'end'];
      function.Script = str;

    Whether to comment out the MATLAB function, specified as a numeric or logical 1 (true) or 0 (false). Setting this property to true is equivalent to right-clicking the MATLAB function and selecting Comment Out. For more information, see Commenting Stateflow Objects in a Chart.

    This property is read-only.

    Whether the MATLAB function is implicitly commented out, specified as a numeric or logical 1 (true) or 0 (false). The MATLAB function is implicitly commented out when you comment out a state, box, or function that contains it.

    Comment text for the MATLAB function, specified as a character vector. This property applies only when the IsExplicitlyCommented property is true. In the Stateflow Editor, when you point to the comment badge on the MATLAB function, the text appears as a tooltip. When you set the IsExplicitlyCommented property to false, the value of CommentText reverts to ''.

    Graphical Appearance

    Position and size of the MATLAB function, specified as a four-element numeric vector of the form [left top width height].

    This property is read-only.

    Whether the MATLAB function graphically intersects a box, state, or function, specified as a numeric or logical 1 (true) or 0 (false).

    Font size for the MATLAB function label, specified as a scalar. The StateFont.Size property of the chart that contains the graphical function sets the initial value of this property.

    Integer and Fixed-Point Data

    Whether the data in the MATLAB function saturates on integer overflow, specified as a numeric or logical 1 (true) or 0 (false). When this property is disabled, the data in the function wraps on integer overflow. For more information, see Handle Integer Overflow for Chart Data.

    This property applies only when the ActionLanguage of the chart that contains the function is 'C'. Otherwise, the behavior of data depends on the value of the SaturateOnIntegerOverflow property for the chart.

    Default fimath properties for the MATLAB function, specified as one of these values:

    • 'Same as MATLAB Default' — Use the same fimath properties as the current default fimath object.

    • 'Other:UserSpecified' — Use the InputFimath property to specify the default fimath object.

    This property applies only when the ActionLanguage of the chart that contains the function is 'C'. Otherwise, the behavior of data depends on the value of the EmlDefaultFimath property for the chart.

    Default fimath object, specified as a character vector. When the EmlDefaultFimath property for the MATLAB function is 'Other:UserSpecified', you can use this property to:

    • Enter an expression that constructs a fimath object.

    • Enter the variable name for a fimath object in the MATLAB or model workspace.

    This property applies only when the ActionLanguage of the chart that contains the function is 'C'. Otherwise, the behavior of data depends on the value of the InputFimath property for the chart.

    Code Generation

    Appearance of the MATLAB function in generated code, specified as one of these values:

    • 'Auto' — An internal calculation determines the appearance of the function in generated code.

    • 'Function' — The function is implemented as a separate C function.

    • 'Inline' — Calls to the function are replaced by code.

    For more information, see Inline State Functions in Generated Code (Simulink Coder).

    Hierarchy

    This property is read-only.

    Chart that contains the MATLAB function, specified as a Stateflow.Chart object.

    This property is read-only.

    Subviewer for the MATLAB function, specified as a Stateflow.Chart, Stateflow.State, Stateflow.Box, or Stateflow.Function object. The subviewer is the chart or subchart where you can graphically view the MATLAB function.

    This property is read-only.

    Machine that contains the MATLAB function, specified as a Stateflow.Machine object.

    This property is read-only.

    Location of the parent of the MATLAB function in the model hierarchy, specified as a character vector.

    Identification

    Description for the MATLAB function, specified as a character vector.

    Document link for the MATLAB function, specified as a character vector.

    User-defined tag for the MATLAB function, specified as data of any type.

    This property is read-only.

    Session-independent identifier, specified as an integer scalar. Use this property to distinguish the MATLAB function from other objects in the model.

    This property is read-only.

    Unique identifier, specified as an integer scalar. Unlike SSIdNumber, the value of this property is reassigned every time you start a new MATLAB session and may be recycled after an object is deleted.

    Object Functions

    findIdentify specified objects in hierarchy
    getChildrenIdentify children of object
    getParentIdentify parent of object
    dialogOpen properties dialog box
    isCommentedDetermine if graphical object is commented out
    viewDisplay object in editing environment
    highlightHighlight graphical object
    fitToViewZoom in on graphical object

    Examples

    collapse all

    Add a MATLAB function in the chart ch. Set its label to '[y1,y2] = f(x1,x2,x3)'.

    function = Stateflow.EMFunction(ch);
    function.LabelString = '[y1,y2] = f(x1,x2,x3)';
    Introduced before R2006a