Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Introduction to Embedded MATLAB Function Blocks

What Is an Embedded MATLAB Function Block?

The Embedded MATLAB Function block allows you to add MATLAB functions to Simulink models for deployment to embedded processors. This capability is useful for coding algorithms that are better stated in the textual language of the MATLAB software than in the graphical language of the Simulink product. This block works with a subset of the MATLAB language called the Embedded MATLAB subset, which provides optimizations for generating efficient, production-quality C code for embedded applications. For more information, see Working with the Embedded MATLAB Subset in the MATLAB documentation. For more information on fixed-point support in MATLAB, refer to Working with the Fixed-Point Embedded MATLAB Subset in the Fixed-Point Toolbox documentation.

Example: Calculating Statistical Mean and Standard Deviation

Here is an example of a Simulink model that contains an Embedded MATLAB Function block:

You will build this model in Creating an Example Embedded MATLAB Function.

Defining Local Variables.   Note in this Embedded MATLAB function that you can declare local variables implicitly through assignment, just as you would in MATLAB functions. The variable takes its type and size from the context in which it is assigned. For example, the following code line declares x to be a scalar variable of type double.

x = 1.54;

Once you define a variable, you cannot redefine it to any other type or size in the function body. For example, you cannot declare x and reassign it:

x = 2.65; % OK: x is a scalar double
x = [x 2*x]; % Error: x cannot be changed to a vector

See Creating Local Complex Variables By Assignment in the Embedded MATLAB documentation for detailed descriptions and examples.

Declaring Extrinsic Functions.   Note in this example, that you can declare functions to be extrinsic by using eml.extrinsic. This ensures that the Embedded MATLAB software does not attempt to compile this function. Instead, the function will execute in the MATLAB workspace during simulation of the model. For example, the following code declares the plot function to be extrinsic:

eml.extrinsic('plot');

See Calling Embedded MATLAB Library Functions in the Embedded MATLAB documentation for more information.

Calling Functions in Embedded MATLAB Function Blocks

In addition to supporting a rich subset of the MATLAB language, Embedded MATLAB Function blocks can call any of the following types of functions:

Why Use Embedded MATLAB Function Blocks?

Embedded MATLAB Function blocks provide the following capabilities:

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS