Why do I get error when I try to create my own function directive in my TLC file using Simulink Coder 8.1 (R2011b)?

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.

 採用された回答

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.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

製品

リリース

R2011b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by