coder.config - Create code generation configuration objects - MATLAB (original) (raw)
Create code generation configuration objects
Syntax
Description
Use the coder.config
function to create configuration objects for MEX code generation, standalone code generation, fixed-point conversion, and single-precision conversion. Modify the properties of the configuration object to customize the generated code according to your project requirements, such as readability, performance, hardware requirements, and use of custom libraries.
[config_obj](#mw%5F9f206580-a1a9-4bff-bed5-f99c0375b275) = coder.config
creates acoder.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.
[config_obj](#mw%5F9f206580-a1a9-4bff-bed5-f99c0375b275) = coder.config([build_type](#mw%5F2e61319d-d52d-4d16-9cde-1c1d3b71fc3a))
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.
[config_obj](#mw%5F9f206580-a1a9-4bff-bed5-f99c0375b275) = coder.config([build_type](#mw%5F2e61319d-d52d-4d16-9cde-1c1d3b71fc3a),'ecoder',[ecoder_flag](#mw%5F1eef52d9-941a-4139-a4bd-05d907b25472))
creates a coder.EmbeddedCodeConfig object or acoder.CodeConfig object depending on whether ecoder_flag
is true
orfalse
. build_type
is'lib'
, 'dll'
, or 'exe'
. Set the flag to true
to use these features:
- Code verification through software-in-the-loop (SIL) and processor-in-the-loop (PIL) execution.
- Code tracing or bidirectional traceability.
- Hardware specific optimizations and custom replacement libraries.
- Customize the appearance of the generated code.
See Embedded Coder Capabilities for Code Generation from MATLAB Code (Embedded Coder).
[config_obj](#mw%5F9f206580-a1a9-4bff-bed5-f99c0375b275) = coder.config([numeric_conversion_type](#mw%5Fa9dcda2f-b2e1-479e-88ba-97bdfd289a87))
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 thecodegen
command. - coder.SingleConfig (Fixed-Point Designer) when generating single-precision MATLAB code from double-precision MATLAB code. Use with the
-double2single
option of thecodegen
command.
Fixed-point conversion or single-precision conversion requires Fixed-Point Designer™.
Examples
Generate MEX Function from MATLAB Function
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
Generate Standalone C Static or Dynamic Library or Generate Standalone C Executable
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 with Embedded Coder Installed
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 Numeric Conversion Configuration Object
Input Arguments
build_type
— Type of code generation object to create
'mex' | 'lib' | 'dll' | 'exe'
Configuration Object Type | Generated Code | Code Generation Configuration Object (Embedded Coder installed) | Code Generation Configuration Object (Embedded Coder not installed) |
---|---|---|---|
'mex' | MEX function | coder.MexCodeConfig | coder.MexCodeConfig |
'lib' | Static library | coder.EmbeddedCodeConfig | coder.CodeConfig |
'dll' | Dynamic library | coder.EmbeddedCodeConfig | coder.CodeConfig |
'exe' | Executable | coder.EmbeddedCodeConfig | coder.CodeConfig |
Example: coder.config('mex');
Data Types: char
| string
numeric_conversion_type
— Numeric conversion object type
'fixpt' | 'single'
'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
ecoder_flag
— Embedded Coder code configuration object flag
false | true
true | Creates a coder.EmbeddedCodeConfig configuration object regardless of the presence of Embedded Coder to allow use of the following features: Code verification through software-in-the-loop (SIL) and processor-in-the-loop (PIL) execution.Code tracing or bidirectional traceability.Hardware specific optimizations and custom replacement libraries.Customize the appearance of the generated code See Embedded Coder Capabilities for Code Generation from MATLAB Code (Embedded Coder).build_type must be 'lib', 'dll', or 'exe'.However, code generation by using acoder.EmbeddedCodeConfig object requires the Embedded Coder product. |
---|---|
false | Creates 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
config_obj
— Code generation configuration handle
coder.CodeConfig | coder.MexCodeConfig | coder.EmbeddedCodeConfig | coder.FixPtConfig | coder.SingleConfig
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.
Version History
Introduced in R2011a