Skip to Main Content Skip to Search
Product Documentation

Example of a MATLAB Function 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)
%#codegen

% 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);
coder.extrinsic('plot');
plot(vals,'-+');

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

You will build a similar model in Building a Model with a MATLAB Function in a Chart.

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

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS