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
Input Arguments
parent
— Parent for new MATLAB function
Stateflow.Chart
object | Stateflow.State
object | Stateflow.Box
object | Stateflow.Function
object
Parent for the new MATLAB function, specified as a Stateflow API object of one of these types:
Properties
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
— Name of MATLAB function
""
(default) | string scalar | character vector
Name of the MATLAB function, specified as a string scalar or character vector.
LabelString
— Label for MATLAB function
"?"
(default) | string scalar | character vector
Label for the MATLAB function, specified as a string scalar or character vector.
Script
— Code for MATLAB function
string scalar | character vector
Code for the MATLAB function, specified as a string scalar or 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"); func.Script = str;
Enter a concatenated text expression that uses the function
newline
to create newline characters:str = "function y=f(x)" + newline + ... "y=x+1;" + newline + ... "end"; func.Script = str;
IsExplicitlyCommented
— Whether to comment out MATLAB function
false
or 0 (default) | true
or 1
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 Comment Out Objects in a Stateflow Chart.
IsImplicitlyCommented
— Whether MATLAB function is implicitly commented out
true
or 1 | false
or 0
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 explicitly comment out an
object that contains it. If the MATLAB function is contained in an atomic subchart or an atomic box, this
property is false
unless the explicitly commented object is also
contained in the atomic subchart or atomic box.
IsCommented
— Whether MATLAB function is commented out
true
or 1 | false
or 0
Since R2023a
This property is read-only.
Whether the MATLAB function is commented out, specified as a numeric or logical 1
(true
) or 0 (false
). This property is
true
when either IsExplicitlyCommented
or
IsImplicitlyCommented
is true
.
CommentText
— Comment text
""
(default) | string scalar | character vector
Comment text for the MATLAB function, specified as a string scalar or 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
— Position and size of MATLAB function
[0 0 90 60]
(default) | [left top width height]
Position and size of the MATLAB function, specified as a four-element numeric vector of
the form [left top width height]
.
BadIntersection
— Whether MATLAB function intersects a box, state, or function
true
or 1 | false
or 0
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
).
FontSize
— Font size for MATLAB function label
scalar
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
SaturateOnIntegerOverflow
— Whether data saturates on integer overflow
true
or 1 (default) | false
or 0
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 and Enumeration 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.
EmlDefaultFimath
— Default fimath
properties
"Same as MATLAB Default"
(default) | "Other:UserSpecified"
Default fimath
properties for the MATLAB function, specified as one of these values:
"Same as MATLAB Default"
— Use the samefimath
properties as the current defaultfimath
object."Other:UserSpecified"
— Use theInputFimath
property to specify the defaultfimath
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.
InputFimath
— Default fimath
object
string scalar | character vector
Default fimath
object, specified as a string scalar or 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
InlineOption
— Appearance in generated code
"Auto"
(default) | "Function"
| "Inline"
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 as long as the function is not part of a recursion.
For more information, see Inline State Functions in Generated Code (Simulink Coder).
Hierarchy
Chart
— Chart that contains MATLAB function
Stateflow.Chart
object
This property is read-only.
Chart that contains the MATLAB function, specified as a
Stateflow.Chart
object.
Subviewer
— Subviewer for MATLAB function
Stateflow.Chart
object | Stateflow.State
object | Stateflow.Box
object | Stateflow.Function
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.
Machine
— Machine that contains MATLAB function
Stateflow.Machine
object
This property is read-only.
Machine that contains the MATLAB function, specified as a Stateflow.Machine
object.
Path
— Location of parent in model hierarchy
character vector
This property is read-only.
Location of the parent of the MATLAB function in the model hierarchy, specified as a character vector.
Identification
Description
— Description
""
(default) | string scalar | character vector
Description for the MATLAB function, specified as a string scalar or character vector.
Document
— Document link
""
(default) | string scalar | character vector
Document link for the MATLAB function, specified as a string scalar or character vector.
Tag
— User-defined tag
[]
(default) | any data type
User-defined tag for the MATLAB function, specified as data of any type.
SSIdNumber
— Session-independent identifier
scalar
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 its parent chart.
Id
— Unique identifier
scalar
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
find | Identify specified objects in hierarchy |
getChildren | Identify children of object |
getParent | Identify parent of object |
getReferences | Identify references to symbol name |
renameReferences | Rename symbol and update references to symbol name |
commentedBy | Identify objects that implicitly comment out a graphical object |
dialog | Open properties dialog box |
view | Display object in editing environment |
highlight | Highlight graphical object |
fitToView | Zoom in on graphical object |
Examples
Add MATLAB Function to Chart
Add a MATLAB function in the chart ch
. Set its label to
"[y1,y2] = f(x1,x2,x3)"
.
func = Stateflow.EMFunction(ch);
func.LabelString = "[y1,y2] = f(x1,x2,x3)";
Version History
Introduced before R2006aR2023a: New object functions and properties
Stateflow.EMFunction
objects have new object functions and properties:
The object function
getReferences
returns the locations where a chart refers to the name of a MATLAB function.The object function
renameReferences
renames a MATLAB function and updates all references to the function name in the chart.The object function
commentedBy
identifies the explicitly commented objects that cause a MATLAB function to be commented out.The property
IsCommented
indicates whether a MATLAB function is commented out. This property replaces the object functionisCommented
.
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)