This is machine translation

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

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

What is C Code Generation from MATLAB?

You can use WLAN System Toolbox™ together with MATLAB® Coder™ to create C/C++ code that implements your MATLAB functions and models. With this software, you can

  • Create a MEX file to speed up your own MATLAB application.

  • Generate a stand-alone executable that runs independently of MATLAB on your own computer or another platform.

  • Include System objects in the same way as any other element.

In general, the code you generate using the toolbox is portable ANSI® C code. In order to use code generation, you need a MATLAB Coder license. Using WLAN System Toolbox requires licenses for DSP System Toolbox™, Signal Processing Toolbox™, and Communications System Toolbox™. See the Getting Started with MATLAB Coder (MATLAB Coder) page for more information.

Creating a MATLAB Coder MEX-file can lead to substantial acceleration of your MATLAB algorithms. It is also a convenient first step in a workflow that ultimately leads to completely standalone code. When you create a MEX-file, it runs in the MATLAB environment. Its inputs and outputs are available for inspection just like any other MATLAB variable. You can use MATLAB’s visualization, and other tools, for verification and analysis.

Within your code, you can run specific commands either as generated C code or by running using the MATLAB engine. In cases where an isolated command does not yet have code generation support, you can use the coder.extrinsic command to embed the command in your code. This means that the generated code reenters the MATLAB environment when it needs to run that particular command. This also useful if you wish to embed certain commands that cannot generate code (such as plotting functions).

The simplest way to generate MEX-files from your MATLAB code is by using the codegen function at the command line. Often, generating a MEX-files involves nothing more than invoking the coder command on one of your existing functions. For example, if you have an existing function, myfunction.m, you can type the commands at the command line to compile and run the MEX function. codegen adds a platform-specific extension to this name. In this case, the "mex" suffix is added.

codegen myfunction.m

You can generate standalone executables that run independently of the MATLAB environment. You can do this by creating a MATLAB Coder project inside the MATLAB Coder Integrated Development Environment (IDE). Alternatively, you can issue the codegen command in the command line environment with appropriate configuration parameters. To create a standalone executable, you must write your own main.c or main.cpp function. See C/C++ Code Generation (MATLAB Coder) for more information.

Set Up Your Compiler

Before using codegen to compile your code, you must set up your C/C++ compiler. For 32-bit Windows platforms, MathWorks® supplies a default compiler with MATLAB. If your installation does not include a default compiler, you can supply your own compiler. For the current list of supported compilers, see Supported and Compatible Compilers on the MathWorks Web site. Install a compiler that is suitable for your platform. Then, read Setting Up the C or C++ Compiler (MATLAB Coder). After installation, at the MATLAB command prompt, run mex -setup. You can then use the codegen function to compile your code.

Functions and System Objects That Support Code Generation

All WLAN System Toolbox functions and System objects are supported for code generation. For a list of supported functions and System objects, see WLAN System Toolbox (MATLAB Coder).

Was this topic helpful?