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;
Note in this example that the MATLAB function can call any of these types of functions:
Local functions are defined in the body of the MATLAB function. In this example,
avg is a local
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,
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.