| Using Simulink | ![]() |
What Is an Embedded MATLAB Function Block?
The Embedded MATLAB Function block contains a MATLAB function in a Simulink model. The function accepts multiple input signals and produces multiple output signals.
You build the following model in Creating an Example Embedded MATLAB Function:
As in a MATLAB function, in the Embedded MATLAB Function block, you can declare a local variable implicitly through assignment. 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.
Once you define a variable, it cannot be redefined to any other type or size in the function body. For example, you cannot declare x and reassign it as follows:
See Declaring Local Variables Implicitly for detailed descriptions and examples.
In addition to supporting a rich subset of the MATLAB language, an Embedded MATLAB Function block can call any of the following functions:
Subfunctions are defined in the body of the Embedded MATLAB block. In the preceding example, avg is a subfunction.
Embedded MATLAB run-time library functions are a subset of the functions that you call in MATLAB. When you build targets for your model, these functions generate C code that conforms to the memory and variable type requirements of embedded environments. In the preceding example, length, sqrt, and sum are Embedded MATLAB run-time library functions.
Function calls that cannot be resolved as subfunctions or Embedded MATLAB run-time library functions are resolved in the MATLAB workspace. These functions do not generate code; they execute only in the MATLAB workspace during simulation of the model.
| Introduction to Embedded MATLAB Function Blocks | Why Use Embedded MATLAB Function Blocks? | ![]() |
© 1994-2005 The MathWorks, Inc.