This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Determine if code generation target is specified target


tf =



tf = returns true (1) if the code generation target is 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 in MATLAB class property initialization,'MATLAB') returns true.


collapse all

Parameterize a MATLAB function so that it works in MATLAB or 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 the C library for myabsval.m, using the -args option to specify the size, type, and complexity of the input parameter.

codegen -config:lib myabsval -args {0.0}
codegen creates the library myabsval.lib and header file myabsval.h in the folder /codegen/lib/myabsval. It also 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  %#codegen
y = -2.75;
% Check the target. Do not use coder.ceval if callmyabsval is
% executing in MATLAB
  % Executing in MATLAB, call function myabsval
  y = myabsval(y);
  % Executing in the generated code. 
  % Call the initialize function before calling the 
  % C function for the first time

  % 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

Convert callmyabsval.m to the MEX function callmyabsval_mex.

codegen -config:mex callmyabsval codegen/lib/myabsval/myabsval.lib...

Run the MATLAB function callmyabsval .

ans =


Run the MEX function callmyabsval_mex which calls the library function myabsval.

ans =


Input Arguments

collapse all

Code generation target specified as one of the following values.

'MATLAB'Running in MATLAB (not generating code)
'MEX'Generating a MEX function
'Sfun'Simulating a Simulink® model
'Rtw'Generating a LIB, DLL, or EXE target
'HDL 'Generating an HDL target
'Custom'Generating a custom target

Example: tf ='MATLAB')

See Also

Introduced in R2011a

Was this topic helpful?