User`s guide

4 Guidelines for Writing C MEX S-Functions
4-22
The following graph illustrates how the parameters XData=[1:6],
YData=[1,2,7,4,5,9] are handled. For example, if the input (x-value) to the
S-function block is 3, then the output (y-value) is 7.
Figure 4-3: Typical Output from a Lookup Table Example
The Direct-Index Lookup Table Example
This secti on shows how to improve the lookup ta ble by inlining a d irect-index
S-function with a TLC fi le . Note that this d irect-index lo ok up table S-f unctio n
doesn’trequire a TLCf ile for it to work withtheReal-Time Workshop . Here the
example use s a TLC file for the direct -index lookup t able S-function to reduce
the code size and increase efficiency of the generated code.
Implementation of th e dire c t- ind e x algorithm w ith inlined TLC file require s
the S-function main module,
sfun_directlook.c (see page 4–27) and a
corresponding
lookup_index.c module (s ee page 4–36). T he lookup_index.c
module contains the GetDirectLookupIndex routinethatisusedtolocatethe
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
1
2
3
4
5
6
7
8
9