coder.target
Determine if code generation target is specified target
Description
returns
true (1) if the code generation target is tf
= coder.target(target
)target
.
Otherwise, it returns false (0).
If you generate code for MATLAB® classes, MATLAB computes
class initial values at class loading time before code generation.
If you use coder.target
in MATLAB class
property initialization, coder.target('MATLAB')
returns
true.
Examples
Use coder.target
to Parameterize a MATLAB Function
Parameterize a MATLAB function so that it works in MATLAB or in generated code. When the function runs in MATLAB, it calls the MATLAB function myabsval
. The generated code, however, calls a
C library function myabsval
.
Write a MATLAB function
myabsval
.
function y = myabsval(u) %#codegen y = abs(u);
Generate a C static library for myabsval
, using the
-args
option to specify the size, type, and complexity of the input
parameter.
codegen -config:lib myabsval -args {0.0}
codegen
function creates the library file
myabsval.lib
and header file myabsval.h
in the
folder \codegen\lib\myabsval
. (The library file extension can change
depending on your platform.) It generates the functions
myabsval_initialize
and myabsval_terminate
in
the same folder.Write a MATLAB function to call the generated C library function using
coder.ceval
.
function y = callmyabsval(y) %#codegen % Check the target. Do not use coder.ceval if callmyabsval is % executing in MATLAB if coder.target('MATLAB') % Executing in MATLAB, call function myabsval y = myabsval(y); else % add the required include statements to generated function code coder.updateBuildInfo('addIncludePaths','$(START_DIR)\codegen\lib\myabsval'); coder.cinclude('myabsval_initialize.h'); coder.cinclude('myabsval.h'); coder.cinclude('myabsval_terminate.h'); % Executing in the generated code. % Call the initialize function before calling the % C function for the first time coder.ceval('myabsval_initialize'); % Call the generated C library function myabsval y = coder.ceval('myabsval',y); % Call the terminate function after % calling the C function for the last time coder.ceval('myabsval_terminate'); end
Generate the MEX function callmyabsval_mex
. Provide the
generated library file at the command line.
codegen -config:mex callmyabsval codegen\lib\myabsval\myabsval.lib -args {-2.75}
Rather than providing the library at the command line, you can use coder.updateBuildInfo
to specify the
library within the function. Use this option to preconfigure the build. Add this line to
the else
block:
coder.updateBuildInfo('addLinkObjects','myabsval.lib','$(START_DIR)\codegen\lib\myabsval',100,true,true);
Run the MEX function callmyabsval_mex
which calls the library
function
myabsval
.
callmyabsval_mex(-2.75)
ans = 2.7500
Call the MATLAB function
callmyabsval
.
callmyabsval(-2.75)
ans = 2.7500
callmyabsval
function exhibits the desired behavior for execution
in MATLAB and in code generation.Input Arguments
target
— code generation target
'MATLAB'
| 'C'
| 'C++'
| 'CUDA'
| 'HLS'
| 'SystemVerilog'
| 'Verilog'
| 'VHDL'
| 'MEX'
| 'Sfun'
| 'Rtw'
| 'HDL '
| 'Custom'
Code generation target, specified as a character vector or a string scalar. Specify one of these targets.
'MATLAB' | Running in MATLAB (not generating code) |
| Supported target languages for code generation |
'MEX' | Generating a MEX function |
'Sfun' | Simulating a Simulink® model. Also used for running in Accelerator mode. |
'Rtw' | Generating a LIB, DLL, or EXE target. Also used for running in Simulink Coder™ and Rapid Accelerator mode. |
'HDL' | Generating an HDL target |
'Custom' | Generating a custom target |
Example: tf = coder.target('MATLAB')
Example: tf = coder.target("MATLAB")
Note
In case of CUDA
or High-Level Synthesis (HLS)
code
generation, coder.target('C++')
is always
true
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
Introduced in R2011a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)