| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Embedded MATLAB |
| Contents | Index |
| On this page… |
|---|
In Compiling M-Code Using emlmex, you generated a MEX function for your M-code by calling emlmex from the MATLAB command line. In this part of the tutorial, you use a build script to generate your MEX function.
Best Practice — Using Build Scripts
Best Practice — File Naming Convention
The build script file emldemo_lms_build_02_mex.m supplied with this tutorial contains.
close all;
clear all;
clc;
N = 73113;
emlmex emldemo_lms_02 -eg { zeros(N,1) zeros(N,1) } ...
-report -o emldemo_lms_02_mex
where:
The first three commands initialize the MATLAB computing environment in preparation for the remainder of the script.
close all deletes all figures whose handles are not hidden. See close in the MATLAB Graphics function reference for more information.
clear all removes all variables, functions, and MEX-files from memory, leaving the workspace empty. It also clears all breakpoints.
clc clears all input and output from the Command Window display, giving you "clean screen".
N = 73113 sets the music sample size to the size of the handel.mat audio sample. You need the audio sample length to specify the size of the emldemo_lms_02 function input parameters. See Compiling M-Code Using emlmex for more information.
emlmex is a command that:
Compiles the file emldemo_lms_02.m, which contains the same code as the file my_emldemo_lms_01_compliant.m that you saved at the end of Compiling M-Code Using emlmex. You can verify that these two files are the same by using the MATLAB Compare Against option.
Uses the -eg option to instruct emlmex to compile the file using the sample input parameters { zeros(N,1) zeros(N,1) }. The -eg option provides Embedded MATLAB with examples or prototypes of the input variables, specifying their data types, array dimensions, and numeric complexity but not their actual values. In this case, the prototypes are N-by-1 vectors of all zeros represented as real-valued, double-precision floating-point numbers.
Uses the -report option to instruct emlmex to generate a compilation report.
Uses the -o option to instruct emlmex to generate the MEX function in a file named emldemo_lms_02_mex.
See Recommended Compilation Options for emlmex for more information.
To use the build script emldemo_lms_build_02_mex.m to generate a MEX function for emldemo_lms_02.m:
Set your MATLAB current folder to the folder that contains your files for this tutorial. At the MATLAB command line, enter:
cd folder
where folder is the full path name of the folder containing the files. See Viewing and Changing the Current Folder Using the Current Folder Browser in the MATLAB Desktop Tools and Development Environment documentation for more information.
Run the build script by typing emldemo_lms_build_02_mex at the MATLAB command prompt.
emlmex processes the build file and outputs the message:
C-MEX generation successful: Open coder report.
Verify that the output file emldemo_lms_02_mex is in the current folder.
Note The file extension you see depends on the platform on which you are running. MATLAB adds a platform-specific file extension to the MEX output file. for example. For example, on 32-bit Windows platforms, the output file is emldemo_lms_02_mex.mexw32. See Naming Conventions in the Embedded MATLAB User's Guide for more information. |
![]() | Testing Compliant Code in MATLAB | Testing MEX Functions | ![]() |

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 |