MATLAB: Do I get error when I try to create the own function directive in the TLC file using Simulink Coder 8.1 (R2011b)

libnulls-functionsimulink coder

I am writing a tlc file to inline my S-function, and I have created my own user defined function within the tlc, for example:
%function fMax(x, y)
%if (x > y)
.
.
.
%endfunction
The tlc file gives the error:
Error: File: sFunc.tlc Line: 21 Column: 12
The > operator only works on numeric arguments
Even when changing the input and syntax I give to my user defined function in the tlc, I continue to see similar error messages.

Best Answer

In general, the %function directive is used to follow the S-Function API rather than to create user defined functions.
To call an externally defined C function you can add source and header files using SLibAddToStaticSources and LibAddToCommonIncludes. This will allow you to call a user defined function within the tlc. For example, to include the files use:
%<LibAddToCommonIncludes("fmax.h")>
%<SLibAddToStaticSources("fmax.c")>
to call the function, use:
%<z> = fmax(x, y);
It is a good idea to start with the legacy code tool, which can generate an S-Function and TLC-file from a custom C-file, then if needed customize the TLC code of your S-Function.