Main Content


Accelerate fixed-point code or convert floating-point MATLAB code to fixed-point MATLAB code



fiaccel -options fcn translates the MATLAB® file fcn.m to a MEX function, which accelerates fixed-point code. To use fiaccel, your code must meet one of these requirements:

  • The top-level function has no inputs or outputs, and the code uses fi.

  • The top-level function has an output or a non-constant input, and at least one output or input is a fi.

  • The top-level function has at least one input or output containing a built-in integer class (int8, uint8, int16, uint16, int32, uint32, int64, or uint64), and the code uses fi.


fiaccel -float2fixed fcn converts the floating-point MATLAB function, fcn to fixed-point MATLAB code.


collapse all

This example shows how to accelerate fixed-point MATLAB code using the fiaccel function.

Define a function that computes the moving average.

function [avg,z] = moving_average(x,z)

if nargin < 2
    z = fi(zeros(10,1),1,16,15);

z(2:end) = z(1:end-1);  % Update buffer
z(1) = x;               % Add new value
avg = mean(z);          % Compute moving average

Create a test file.

function avg = test_moving_average(x)

if nargin < 1
    x = fi(rand(100,1),1,16,15);

z = fi(zeros(10,1),1,16,15);
avg = x;
for k = 1:length(x)
    [avg(k),z] = moving_average(x(k),z);

Use the fiaccel function to create a MEX function and accelerate the MATLAB code.

x = fi(rand(100,1),1,16,15);
fiaccel test_moving_average -args {x} -report

Compare the non-accelerated and accelerated code.

tic; avg = test_moving_average(x); toc       % Non-compiled version
tic; avg = test_moving_average_mex(x); toc   % Compiled version

Create a coder.FixptConfig object, fixptcfg, with default settings.

fixptcfg = coder.config('fixpt');

Set the test bench name. In this example, the test bench function name is dti_test.

fixptcfg.TestBenchName = 'dti_test';

Convert a floating-point MATLAB function to fixed-point MATLAB code. In this example, the MATLAB function name is dti.

fiaccel -float2fixed fixptcfg dti

Input Arguments

collapse all

MATLAB function to generate MEX from, specified as a function existing in the current working folder or on the path.


If your top-level file is on a path that contains Unicode characters, code generation might not be able to find the file.

Compiler options, specified as a space delimited list of option values. fiaccel gives precedence to individual command-line options over options specified using a configuration object. If command-line options conflict, the right-most option prevails.

Specified as one or more of these values:

-args example_inputs

Define the size, class, and complexity of MATLAB function inputs by providing a cell array of example input values. The position of the example input in the cell array must correspond to the position of the input argument in the MATLAB function definition. To generate a function that has fewer input arguments than the function definition has, omit the example values for the arguments that you do not want.

Specify the example inputs immediately after the function to which they apply.

Instead of an example value, you can provide a coder.Type object. To create a coder.Type object, use the coder.typeof function.

-config config_object

Specify MEX generation parameters, based on config_object, defined as a MATLAB variable using coder.mexconfig.

For example:

cfg = coder.mexconfig;

-d out_folder

Store generated files in the absolute or relative path specified by out_folder. If the folder specified by out_folder does not exist, fiaccel creates it for you.

If you do not specify the folder location, fiaccel generates files in the default folder fiaccel/mex/fcn, where fcn is the name of the MATLAB function specified at the command line.

The function does not support the following characters in folder names: asterisk (*), question-mark (?), dollar ($), and pound (#).

-float2fixed float2fixed_cfg_name

Generates fixed-point MATLAB code using the settings specified by the floating-point to fixed-point conversion configuration object named float2fixed_cfg_name.

For this option, fiaccel generates files in the folder codegen/fcn_name/fixpt.

You must set the TestBenchName property of float2fixed_cfg_name.

For example:

fixptcfg.TestBenchName = 'myadd_test';
specifies that myadd_test is the test file for the floating-point to fixed-point configuration object fixptcfg.

You cannot use this option with the -global option.


Compiles the MEX function in debug mode, with optimization turned off. If not specified, fiaccel generates the MEX function in optimized mode.

-global global_values

Specify initial values for global variables in MATLAB file. Use the values in cell array global_values to initialize global variables in the function you compile. The cell array should provide the name and initial value of each global variable. You must initialize global variables before compiling with fiaccel. If you do not provide initial values for global variables using the -global option, fiaccel checks for the variable in the MATLAB global workspace. If you do not supply an initial value, fiaccel generates an error.

The generated MEX code and MATLAB each have their own copies of global data. To ensure consistency, you must synchronize their global data whenever the two interact. If you do not synchronize the data, their global variables might differ.

You cannot use this option with the -float2fixed option.

-I include_path

Add include_path to the beginning of the code generation path.

fiaccel searches the code generation path first when converting MATLAB code to MEX code.


Generate and open a code generation report. If you do not specify this option, fiaccel generates a report only if error or warning messages occur or you specify the -report option.


Specify the number of output arguments in the generated entry-point function. The code generator produces the specified number of output arguments in the order in which they occur in the MATLAB function definition.

-o output_file_name

Generate the MEX function with the base name output_file_name plus a platform-specific extension.

output_file_name can be a file name or include an existing path.

If you do not specify an output file name, the base name is fcn_mex, which allows you to run the original MATLAB function and the MEX function and compare the results.

-O optimization_option

Optimize generated MEX code, based on the value of optimization_option:

  • enable:inline — Enable function inlining

  • disable:inline — Disable function inlining

If not specified, fiaccel uses inlining for optimization.


Generate a code generation report. If you do not specify this option, fiaccel generates a report only if error or warning messages occur or you specify the -launchreport option.


Display help for fiaccel command.

Version History

Introduced in R2011a

expand all