Products & Services Solutions Academia Support User Community Company

Generating C Code Using emlc

Prerequisites for Generating C Code

To use emlc, you must install Real-Time Workshop and its prerequisite products:

For instructions on installing and setting up a C compiler, see Setting Up the C Compiler in the Real-Time Workshop User's Guide.

Contents of the Example Build Script

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:lib

where:

Using the Example Build Script

To generate C code:

  1. Set your MATLAB current folder to the folder that contains your files for this tutorial.

  2. 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.
  3. To view the compilation report, click the Open compilation report. link.

    The Embedded MATLAB Compilation Report appears.

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

  5. 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.

      Note   The generated C code is in folder\emcprj\rtwlib\emldemo_lms_02, where folder is the folder that contains your tutorial files.

  6. Close the error report and emldemo_lms_02.c file.

Comparing the Generated C Code to Original M-Code

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:

Next Task

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.

  


Recommended Products

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