This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

MATLAB Functions in a Stateflow Chart

The following model contains a Stateflow® chart with a MATLAB® function.

The chart contains the following logic:

The function contains the following code:

function stats(vals)

% calculates a statistical mean and standard deviation
% for the values in vals.

len = length(vals);
mean = avg(vals, len);
stdev = sqrt(sum(((vals-avg(vals,len)).^2))/len);

function mean = avg(array,size)
mean = sum(array)/size;

Note in this example that the MATLAB function can call any of these types of functions:

  • Local functions

    Local functions are defined in the body of the MATLAB function. In this example, avg is a local function.

  • Stateflow functions

    Graphical, truth table, and other MATLAB functions can be called from a MATLAB function in a chart.

  • MATLAB toolbox functions that support code generation

    Toolbox functions for code generation are a subset of the functions that you can call in the MATLAB workspace. These functions generate C code for building targets that conform to the memory and data type requirements of embedded environments. In this example, length, sqrt, and sum are examples of toolbox functions for code generation.

  • MATLAB toolbox functions that do not support code generation

    You can also call extrinsic functions on the MATLAB path that do not generate code. These functions execute only in the MATLAB workspace during simulation of the model.

  • Simulink® Design Verifier™ functions

    Simulink Design Verifier software provides MATLAB functions for property proving and test generation.