MATLAB® Coder™
User's Guide
R2017a
How to Contact MathWorks
Latest news:
Sales and services:
User community:
Technical support:
Phone:
www.mathworks.com
www.mathworks.com/sales_and_services
www.mathworks.com/matlabcentral
www.mathworks.com/support/contact_us
508-647-7000
The MathWorks, Inc.
3 Apple Hill Drive
Natick, MA 01760-2098
MATLAB® Coder™ User's Guide
© COPYRIGHT 2011–2017 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and
govern the use, modification, reproduction, release, performance, display, and disclosure of the Program
and Documentation by the federal government (or other entity acquiring for or through the federal
government) and shall supersede any conflicting contractual terms or conditions. If this License fails
to meet the government's needs or is inconsistent in any respect with federal procurement law, the
government agrees to return the Program and Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
April 2011
Online only
September 2011 Online only
March 2012
Online only
September 2012 Online only
March 2013
Online only
September 2013 Online only
March 2014
Online only
Online only
October 2014
March 2015
Online only
September 2015 Online only
October 2015
Online only
March 2016
Online only
September 2016 Online only
March 2017
Online only
New for Version 2 (R2011a)
Revised for Version 2.1 (Release 2011b)
Revised for Version 2.2 (Release 2012a)
Revised for Version 2.3 (Release 2012b)
Revised for Version 2.4 (Release 2013a)
Revised for Version 2.5 (Release 2013b)
Revised for Version 2.6 (Release 2014a)
Revised for Version 2.7 (Release 2014b)
Revised for Version 2.8 (Release 2015a)
Revised for Version 3.0 (Release 2015b)
Rereleased for Version 2.8.1 (Release
2015aSP1)
Revised for Version 3.1 (Release 2016a)
Revised for Version 3.2 (Release 2016b)
Revised for Version 3.3 (Release 2017a)
Check Bug Reports for Issues and Fixes
Software is inherently complex and is not free of errors. The output of a code generator
might contain bugs, some of which are not detected by a compiler. MathWorks
reports critical known bugs brought to its attention on its Bug Report system at
www.mathworks.com/support/bugreports/. Use the Saved Searches and Watched Bugs
tool with the search phrase "Incorrect Code Generation" to obtain a report of known bugs
that produce code that might compile and execute, but still produce wrong answers.
The bug reports are an integral part of the documentation for each release. Examine
periodically all bug reports for a release, as such reports may identify inconsistencies
between the actual behavior of a release you are using and the behavior described in this
documentation.
In addition to reviewing bug reports, you should implement a verification and validation
strategy to identify potential bugs in your design, code, and tools.
Contents
About MATLAB Coder
MATLAB Coder Product Description . . . . . . . . . . . . . . . . . . .
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Product Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
When to Use MATLAB Coder . . . . . . . . . . . . . . . . . . . . . . . .
Code Generation for Embedded Software Applications . . . . .
Code Generation for Fixed-Point Algorithms . . . . . . . . . . . . .
Code Generation Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . .
See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1-2
1-2
1-3
1-3
1-3
1-3
1-5
1-5
Design Considerations for C/C++ Code Generation
1
2
When to Generate Code from MATLAB Algorithms . . . . . . .
When Not to Generate Code from MATLAB Algorithms . . . .
Which Code Generation Feature to Use . . . . . . . . . . . . . . . . .
Prerequisites for C/C++ Code Generation from MATLAB . . .
MATLAB Code Design Considerations for Code Generation
See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Differences Between Generated Code and MATLAB Code . .
Character Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Order of Evaluation in Expressions . . . . . . . . . . . . . . . . . . . .
Termination Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Size of Variable-Size N-D Arrays . . . . . . . . . . . . . . . . . . . .
2-2
2-2
2-4
2-5
2-6
2-7
2-8
2-8
2-8
2-10
2-10
vii
Size of Empty Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Size of Empty Array That Results from Deleting Elements of an
Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Floating-Point Numerical Results . . . . . . . . . . . . . . . . . . . .
NaN and Infinity Patterns . . . . . . . . . . . . . . . . . . . . . . . . .
Code Generation Target . . . . . . . . . . . . . . . . . . . . . . . . . . .
MATLAB Class Initial Values . . . . . . . . . . . . . . . . . . . . . . .
Variable-Size Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Potential Differences Reporting . . . . . . . . . . . . . . . . . . . . . .
Addressing Potential Differences Messages . . . . . . . . . . . . .
Disabling and Enabling Potential Differences Reporting . . .
Potential Differences Messages . . . . . . . . . . . . . . . . . . . . . . .
Automatic Dimension Incompatibility . . . . . . . . . . . . . . . . .
mtimes No Dynamic Scalar Expansion . . . . . . . . . . . . . . . .
Matrix-Matrix Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Vector-Vector Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Size Mismatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MATLAB Language Features Supported for C/C++ Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MATLAB Features That Code Generation Supports . . . . . .
MATLAB Language Features That Code Generation Does Not
Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-10
2-10
2-11
2-12
2-12
2-12
2-12
2-12
2-13
2-13
2-13
2-15
2-15
2-16
2-16
2-17
2-17
2-20
2-20
2-21
Functions, Classes, and System Objects Supported
for Code Generation
3
Functions and Objects Supported for C/C++ Code Generation
— Alphabetical List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-2
Functions and Objects Supported for C/C++ Code Generation
— Category List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Aerospace Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Arithmetic Operations in MATLAB . . . . . . . . . . . . . . . . . . .
Audio System Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Automated Driving System Toolbox . . . . . . . . . . . . . . . . . .
3-67
3-69
3-69
3-70
3-71
viii
Contents