particular function you want. The Trigonometric Function block operates in a
similar manner but for cos, sin, tan
-1
etc.
11
User Defined Functions & Lookup Tables
User Defined Functions
Sometimes you cannot find the exact function that you want. If this is the case, then try the block
called Fcn. This allows you to enter a mathematical expression using a restricted set of operators
and functions:
To see what is allowed, click on the Help in the block parameters. If you need something a bit
more complicated then you can write your own MATLAB function and use the block MATLAB Fcn:
This block has been configured to call the MATLAB
function myabs, shown left. x is the input and y is the
output.
Notice that the MATLAB function is not stored as a .m
file in the working directory, instead you are editing
code stored within the block itself. This can be seen
from Block: MyModel/MATLAB Function.
If you are using Simulink to create a program using the Real Time Workshop, then you will need to
use the Embedded Matlab Function or an S Function. S functions are used to embedded Matlab, C
or Fortran into your model.
Look Up Tables
If all else fails, then you can use a look up table to define your function.
You need two vectors to do this. A vector of input values and a vector containing the table of
corresponding output values. You enter these in to the appropriate block parameter. For
intermediate values, the output is calculated using interpolation. Extrapolation is used to calculate
values beyond the specified input range. There are a range of look up tables to suit different needs
(e.g. 1-D Lookup Table, 2-D Lookup Table), see the documentation for further details.
|