| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Embedded MATLAB |
| Contents | Index |
| On this page… |
|---|
Prerequisites for Generating C Code Contents of the Example Build Script Using the Example Build Script |
To use emlc, you must install Real-Time Workshop and its prerequisite products:
MATLAB
Simulink
C compiler (a default compiler is supplied with MATLAB)
For instructions on installing and setting up a C compiler, see Setting Up the C Compiler in the Real-Time Workshop User's Guide.
For this exercise, you use the build script emldemo_lms_build_02_lib.m.
emldemo_lms_build_02_lib.m contains:
close all;
clear all;
clc;
N = 73113;
emlc emldemo_lms_02 ...
-eg { zeros(N,1) zeros(N,1) } ...
-report ...
-c ...
-T rtw:libwhere:
clear all removes all variables, functions, and MEX-files from memory, leaving the workspace empty. It also clears all breakpoints.
emlc opens the file emldemo_lms_02 and automatically translates the Embedded MATLAB compliant M-code into C source code.
See Converting MATLAB Code to C Code in the Real-Time Workshop User's Guide for more information.
The -report option instructs emlc to generate a compilation report.
The -c option instructs emlc to generate code only, without compiling the code to an object file.
Best Practice — Generating C Code Only During Development
Phase
The -T option instructs emlc to generate embeddable C code suitable for targeting a shared library instead of generating the default MEX function. See emlc in the Real-Time Workshop Reference for more information.
To generate C code:
Set your MATLAB current folder to the folder that contains your files for this tutorial.
Type emldemo_lms_build_02_lib at the MATLAB command prompt.
MATLAB processes the build file and outputs the message:
Compilation successful: Open compilation report.To view the compilation report, click the Open compilation report. link.
The Embedded MATLAB Compilation Report appears.

Click the C-code tab to display the list of generated C files.

To view the generated C code, click the link to the target source file, for example, emldemo_lms_02.c.
The file appears in the Embedded MATLAB Coder window.

Close the error report and emldemo_lms_02.c file.
To compare your generated C code to the original M-code, open the C file, emldemo_lms_02.c, and the M-file, emldemo_lms_02.m, in the MATLAB Editor. Use the left/right tile feature to view the files side by side by selecting Window > Left/Right Tile. (See Comparing C Code and M-Code Using Tiling in the MATLAB Editor for more information.)

You can easily compare the generated C code to your original M-code. In the generated C code:
Your function name is unchanged.
Your comments are preserved in the same position.
Your variable names are prefixed with eml_.
Note If a variable in your M-code is set to a constant value, it does not appear as a variable in the generated C code. Instead the generated C code contains the actual value of the variable. For example, the variable L is set to 32 in the M-code, so L does not appear in the generated C code, the value 32 appears wherever L is used. |
You have generated C code for your Embedded MATLAB compliant M-code. You are ready to begin the next task in this tutorial, Elaborating Your Algorithm for Embedded Implementation.
![]() | Generating C Code | Elaborating Your Algorithm for Embedded Implementation | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |