필터 지우기
필터 지우기

How do I call custom MATLAB functions in code generation templates (.cgt) files?

조회 수: 11 (최근 30일)
I have a function called "getMatlabVersion.m" in my current folder. I'd like to use it in my custom code generation template file to display the MATLAB version in the banner of each source file.
I have written a .cgt file that has a line with the following:
* MATLAB Version: %<!getMatlabVersion()>
However, when I build the above, I get the following error:
Code Generation 1
Elapsed: 3 sec
Error: File: myCustomTemplate_cgt.tlc
Attempt to call a non-function value: GetMatlabVersion
Error: File: myCustomTemplate_cgt.tlc
Values of NULL type cannot be expanded
How do I call my function within my .cgt file?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 5월 8일
편집: MathWorks Support Team 2024년 5월 8일
Code generation templates are eventually generated into .tlc files if you try to call functions within them. This means you can leverage functions from TLC programming.
In TLC programming, you would use the FEVAL function to call any MATLAB functions. Similarly, you can use the same function n your .cgt file, like so:
* MATLAB Version: %<!getMatlabVersion()>
would become 
* MATLAB Version: %<!FEVAL("getMatlabVersion")>
The above will allow you to call custom MATLAB functions from within your .cgt file.
Another way would be to use the same syntax original syntax
* MATLAB Version: %<!getMatlabVersion()>
but also write a custom file processing template that defines the above function. You would attach this file to the model using "Configuration parameters -> Code generation -> templates -> custom file processing" and put your .tlc file there.
The contents of your custom TLC would look like this:
%function getMatlabVersion() void
%assign outBuffer = ""
%openfile outBuffer
%assign result = FEVAL("getMatlabVersion")
%<result>
%closefile outBuffer
%return outBuffer
%endfunction
This requires knowledge of TLC programming. Refer to the following links for more information on the above:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Code Generation에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by