| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop |
| Contents | Index |
| Learn more about Real-Time Workshop |
emlc -options files fcn
emlc -options files fcn translates the MATLAB® function in fcn .m or fcn.p to an embeddable C library or executable, or to a MEX function, based on compiler options. Optionally, you can specify custom files to include in the build.
fcn |
MATLAB function from which to generate a MEX function, C library, or C executable code. fcn must comply with Embedded MATLAB™ syntax and semantics, a subset of the MATLAB language. |
files |
Space-separated list of custom files to include in generated code. You can include the following types of files:
|
options |
Choice of compiler options. emlc resolves options from left to right. If you specify conflicting options, the rightmost one prevails.
|
Generate a MEX function from an Embedded MATLAB compliant function:
Write a MATLAB function emcrand that generates a random scalar value drawn from the standard uniform distribution on the open interval (0,1):
function r = emcrand() %#eml % The directive %#eml declares the function % to be Embedded MATLAB compliant r = rand();
Generate and run the MEX function:
emlc emcrand emcrand
Generate C executable files from an Embedded MATLAB compliant function. Specify the main C function as a configuration parameter:
Write a MATLAB function emcrand that generates a random scalar value drawn from the standard uniform distribution on the open interval (0,1):
function r = emcrand() %#eml r = rand();
Write a main C function c:\myfiles\main.c that calls emcrand:
/*
** main.c
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
emcrand_initialize();
printf("emcrand=%g\n", emcrand());
emcrand_terminate();
return 0;
}Configure your code generation parameters to include the main C function, then generate the C executable:
rtwcfg = emlcoder.RTWConfig rtwcfg.CustomSource = 'main.c' rtwcfg.CustomInclude = 'c:\myfiles' emlc -T rtw:exe -s rtwcfg emcrand
emlc generates C executables and supporting files in the default folder emcprj/rtwexe/emcrand.
This example shows how to specify a main function as a parameter in the configuration object emlcoder.RTWConfig. Alternatively, you can specify the file containing main() separately on the command line. This file can be a source, object, or library file.
Generate C library files in a custom folder from an Embedded MATLAB compliant function with inputs of different classes and sizes. The first input is a 1–by-4 vector of unsigned 16–bit integers; the second input is a double-precision scalar:
Write a MATLAB function emcadd that returns the sum of two values:
function y = emcadd(u,v) %#eml y = u + v;
Generate the C library files in a custom folder emcaddlib:
emlc -T rtw:lib -d emcaddlib -eg {zeros(1,4,'uint16'),0} emcaddGenerate C library files from an Embedded MATLAB compliant function that takes a fixed-point input:
Write an M-function emcsqrtfi that computes the square root of a fixed-point input:
function y = emcsqrtfi(x) %#eml y = sqrt(x);
Define numerictype and fimath properties for the fixed-point input x and generate C library code for emcsqrtfi:
T = numerictype('WordLength',32, ...
'FractionLength',23, ...
'Signed',true)
F = fimath('SumMode','SpecifyPrecision', ...
'SumWordLength',32, ...
'SumFractionLength',23, ...
'ProductMode','SpecifyPrecision', ...
'ProductWordLength',32, ...
'ProductFractionLength',23)
% Define a fixed-point variable with these
% numerictype and fimath properties
myfiprops = {fi(4.0,T,F)}
emlc -T rtw:lib -eg myfiprops emcsqrtfiemlc generates C library and supporting files in the default folder emcprj/rtwlib/emcsqrtfi.
You can use a GUI to modify parameters for code generation with emlc:
To modify hardware implementation parameters using a dialog box:
hw_config = emlcoder.HardwareImplementation open hw_config
To modify C code generation parameters using a dialog box:
rtw_config = emlcoder.RTWConfig open rtw_config
To modify MEX code generation parameters using a dialog box:
mex_config = emlcoder.MEXConfig open mex_config
emlmex | fi | fimath | mex | numerictype
![]() | addTMFTokens | findIncludeFiles | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |