Main Content


Class: coder.MATLABCodeTemplate
Namespace: coder

Emit comments for template section


sectionComments = emitSection(sectionName,isCPPComment)


sectionComments = emitSection(sectionName,isCPPComment) emits comments for the code template section that sectionName specifies. If isCPPComment is true, emitSection uses C++ style comments. If emitSection is false, it uses C style comments. Use emitSection to preview banners before you generate code. Before invoking emitSection to emit the banner for a template section, you must set the values for all tokens used in that section.

Input Arguments

expand all

Name of template section specified as one of the following values:


Specify true for C++ style comments. Specify false for C style comments.

Output Arguments

expand all

Comments for the specified section, returned as a character vector.


expand all

This example shows how to set the FileName token value and emit the default file banner.

Create a coder.MATLABCodeTemplate object from the default template.

newObj = coder.MATLABCodeTemplate

Set the FileName token value.

fileN = 'myfilename.c';
newObj.setTokenValue('FileName', fileN)

Emit the file banner.

newObj.emitSection('FileBanner', false)

The emitSection method generates the file banner replacing the FileName token with the file name that you specified. It replaces the MATLABCoderVersion token with the current MATLAB® Coder™ version number. It replaces the SourceGeneratedOn token with the time stamp.

 * File: myfilename.c 
 * MATLAB Coder version            : 2.7 
 * C/C++ source code generated on  : 07-Apr-2014 17:43:32 

This example shows how to create and modify a custom code generation template (CGT) file. It shows how to emit the include files section banner from the custom CGT file.

Create a local copy of the default CGT file for MATLAB Coder. Name it myCGTFile.cgt.

In your local copy of the CGT File, in the IncludeFilesBanner open tag, change the style to "box".

<IncludeFilesBanner style="box">
Include Files

Create a MATLABCodeTemplate object from your custom CGT file.

CGTFile = 'myCGTFile.cgt';
newObj= coder.MATLABCodeTemplate(CGTFile); 

Emit the include files section banner using C++ style comments.

newObj.emitSection('IncludeFilesBanner', true)

The emitSection method generates the include files section banner using the box style with C++ style comments.

// Include Files                                                              //