Main Content

Using Build Scripts

If you use codegen to generate code from the command line, use build scripts to call codegen to generate MEX functions from your MATLAB® function.

A build script automates a series of MATLAB commands that you want to perform repeatedly from the command line, saving you time and eliminating input errors. For instance, you can use a build script to clear your workspace before each build and to specify code generation options.

Here is an example of a build script to run codegen to process lms_02.m:

close all;
clear all;
clc;

N = 73113;

codegen  -report lms_02.m ...
  -args { zeros(N,1) zeros(N,1) }  
where:

  • close all deletes figures whose handles are not hidden. See close in the MATLAB Graphics function reference for more information.

  • clear all removes variables, functions, and MEX-files from memory, leaving the workspace empty. It also clears breakpoints.

    Note

    Remove the clear all command from the build scripts if you want to preserve breakpoints for debugging.

  • clc clears all input and output from the Command Window display, giving you a “clean screen.”

  • N = 73113 sets the value of the variable N, which represents the number of samples in each of the two input parameters for the function lms_02

  • codegen -report lms_02.m -args { zeros(N,1) zeros(N,1) } calls codegen to generate C code for file lms_02.m using the following options:

    • -report generates a code generation report

    • -args { zeros(N,1) zeros(N,1) } specifies the properties of the function inputs as a cell array of example values. In this case, the input parameters are N-by-1 vectors of real doubles.