Main Content

coder.config

Create MATLAB Coder code generation configuration objects

Description

example

config_obj = coder.config creates a coder.MexCodeConfig code generation configuration object for use with codegen when generating a MEX function. Use a coder.MexCodeConfig object with the -config option of the codegen command.

example

config_obj = coder.config(build_type) creates a code generation configuration object for use with codegen when generating a MEX function or standalone code (static library, dynamically linked library or executable program). Use the code generation configuration object with the -config option of the codegen command.

example

config_obj = coder.config(build_type,'ecoder',ecoder_flag) creates a coder.EmbeddedCodeConfig object or a coder.CodeConfig object depending on whether ecoder_flag is true or false. build_type is 'lib', 'dll', or 'exe'.

example

config_obj = coder.config(numeric_conversion_type) creates these configuration objects for use with codegen:

  • coder.FixptConfig when generating fixed-point MATLAB® or C/C++ code from floating-point MATLAB code. Use with the -float2fixed option of the codegen command.

  • coder.SingleConfig (Fixed-Point Designer) when generating single-precision MATLAB code from double-precision MATLAB code. Use with the -double2single option of the codegen command.

Fixed-point conversion or single-precision conversion requires Fixed-Point Designer™.

Examples

collapse all

Generate a MEX function from a MATLAB function that is suitable for code generation and enable a code generation report.

Write a MATLAB function, coderand, that generates a random scalar value from the standard uniform distribution on the open interval (0,1).

function r = coderand() %#codegen
% The directive %#codegen declares that the function
% is intended for code generation
r = rand();

Create a code generation configuration object to generate a MEX function.

cfg = coder.config % or cfg = coder.config('mex')

Open the code generation report.

cfg.GenerateReport = true;

Generate a MEX function in the current folder that specifies the configuration object by using the -config option.

% Generate a MEX function and code generation report
codegen -config cfg coderand

Create a code generation configuration object for a standalone C static library.

cfg = coder.config('lib')
% Returns a coder.EmbeddedCodeConfig object if the Embedded 
% Coder product is installed. 
% Otherwise, returns a coder.CodeConfig object.

Create a code generation configuration object to generate a standalone C dynamic library.

cfg = coder.config('dll')
% Returns a coder.EmbeddedCodeConfig object if the Embedded 
% Coder product is installed. 
% Otherwise, returns a coder.CodeConfig object.

Create a code generation configuration object to generate a standalone C executable.

cfg = coder.config('exe')
% Returns a coder.EmbeddedCodeConfig object if the Embedded 
% Coder product is installed. 
% Otherwise, returns a coder.CodeConfig object.

Create a coder.CodeConfig object even when the Embedded Coder® product is installed on your system.

cfg = coder.config('lib','ecoder',false)

Create a coder.EmbeddedCodeConfig object without Embedded Coder.

cfg = coder.config('lib','ecoder',true)

Create a coder.FixptConfig object.

fixptcfg = coder.config('fixpt');

Create a coder.SingleConfig (Fixed-Point Designer) object.

scfg = coder.config('single');

Input Arguments

collapse all

Configuration Object TypeGenerated CodeCode Generation Configuration Object (Embedded Coder installed)Code Generation Configuration Object (Embedded Coder not installed)
'mex'MEX functioncoder.MexCodeConfigcoder.MexCodeConfig
'lib'Static librarycoder.EmbeddedCodeConfigcoder.CodeConfig
'dll'Dynamic librarycoder.EmbeddedCodeConfigcoder.CodeConfig
'exe'Executablecoder.EmbeddedCodeConfigcoder.CodeConfig

Example: coder.config('mex');

Data Types: char | string

'fixpt'

Creates a coder.FixptConfig configuration object for use with codegen when generating fixed-point MATLAB or C/C++ code from floating-point MATLAB code.

'single'

Creates a coder.SingleConfig configuration object for use with codegen when generating single-precision MATLAB code from double-precision MATLAB code.

Example: coder.config('fixpt');

Data Types: char | string

trueCreates a coder.EmbeddedCodeConfig configuration object without Embedded Coder. However, code generation by using a coder.EmbeddedCodeConfig object requires the Embedded Coder product. build_type must be 'lib', 'dll', or 'exe'.
falseCreates a coder.CodeConfig configuration object even if the Embedded Coder product is installed. build_type must be 'lib', 'dll', or 'exe'.

Example: coder.config('lib','ecoder',false);

Data Types: logical

Output Arguments

collapse all

Handle to the MATLAB Coder™ code generation configuration object.

Alternatives

Use the coder function to open the MATLAB Coder app and create a MATLAB Coder project. The app provides a user interface that facilitates adding MATLAB files, defining input parameters, and specifying build parameters.

Introduced in R2011a