Introduction to Stateflow with Applications

Chapter 3: Embedded MATLAB Functions in Stateflow Charts

This chapter describes the procedure for adding Embedded MATLAB functions to Stateflow charts. It begins with an introduction to Embedded MATLAB functions using an example, followed by procedures for building a Simulink model with a Stateflow chart that calls the Embedded MATLAB function. It concludes with a procedure for debugging Embedded MATLAB functions in Stateflow Charts.

3.1 Introduction to Embedded MATLAB Functions

Figure 3.1 below shows a Stateflow Chart in a Simulink model, the Embedded MATLAB function inside the Stateflow Chart, and the Embedded MATLAB function in the Editor window.


Figure 3.1: Example of a Simulink model with a Stateflow Chart that contains an Embedded MATLAB function

The structure of an Embedded MATLAB function is the same as that of a function used with the Embedded MATLAB Function block [*] that is included in the Simulink User-Defined Functions Library. The advantage of adding Embedded MATLAB functions to a Stateflow Chart is the capability of coding algorithms in the textual MATLAB language instead of the Stateflow graphical language.

It is best to illustrate the procedure for building a Simulink model with a Stateflow diagram that calls an Embedded MATLAB function with an example.

Example 3.1

In this example we will build, program, and debug a model with a Stateflow Chart that contains an Embedded MATLAB Function. The Stateflow Chart will accept a matrix and will output the value of its determinant and its inverse matrix. We will build the model in Section 3.2, we will program it in...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Microprocessor and IC Programmers, Compilers, and Debuggers
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.