Code Generation from MATLAB User’s Guide - University of Illinois ...
Code Generation from MATLAB? User's Guide
R2011b
How to Contact MathWorks
Web
comp.soft-sys.matlab
Newsgroup
contact_TS.html Technical Support
suggest@ bugs@ doc@ service@ info@
Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. Code Generation from MATLAB User's Guide ? COPYRIGHT 2007?2011 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 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 patents for more information.
Revision History
March 2007
Online only
September 2007 Online only
March 2008
Online only
October 2008 Online only
March 2009
Online only
September 2009 Online only
March 2010
Online only
September 2010 Online only
April 2011
Online only
September 2011 Online only
New for Release 2007a Revised for Release 2007b Revised for Release 2008a Revised for Release 2008b Revised for Release 2009a Revised for Release 2009b Revised for Release 2010a Revised for Release 2010b Revised for Release 2011a Revised for Release 2011b
Contents
About Code Generation from MATLAB Algorithms
1
Direct Translation of MATLAB Algorithms to C/C++
Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Prerequisites for Code Generation from MATLAB . . . . 1-3
Preparing MATLAB Code for C/C++ and MEX Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Expected Differences in Behavior After Compiling Your
MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Why Are There Differences? . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Character Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Order of Evaluation in Expressions . . . . . . . . . . . . . . . . . . . 1-5 Termination Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Size of Variable-Size N-D Arrays . . . . . . . . . . . . . . . . . . . . . 1-6 Floating-Point Numerical Results . . . . . . . . . . . . . . . . . . . . 1-7 NaN and Infinity Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Code Generation Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7
MATLAB Language Features Supported for Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
MATLAB Language Features Not Supported for Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11
Related Products That Support Code Generation from
MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
v
Functions Supported for Code Generation
2
About Code Generation for Supported Functions . . . . . 2-2
Functions Supported for Code Generation --
Alphabetical List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Functions Supported for Code Generation --
Categorical List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-59 Aerospace Toolbox Functions . . . . . . . . . . . . . . . . . . . . . . . . 2-60 Arithmetic Operator Functions . . . . . . . . . . . . . . . . . . . . . . 2-60 Bit-Wise Operation Functions . . . . . . . . . . . . . . . . . . . . . . . 2-61 Casting Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-61 Communications System Toolbox Functions . . . . . . . . . . . . 2-62 Complex Number Functions . . . . . . . . . . . . . . . . . . . . . . . . . 2-62 Computer Vision System Toolbox Functions . . . . . . . . . . . . 2-63 Data Type Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-64 Derivative and Integral Functions . . . . . . . . . . . . . . . . . . . . 2-64 Discrete Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-64 Error Handling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 2-65 Exponential Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-65 Filtering and Convolution Functions . . . . . . . . . . . . . . . . . . 2-66 Fixed-Point Toolbox Functions . . . . . . . . . . . . . . . . . . . . . . . 2-66 Histogram Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-75 Image Processing Toolbox Functions . . . . . . . . . . . . . . . . . . 2-75 Input and Output Functions . . . . . . . . . . . . . . . . . . . . . . . . 2-76 Interpolation and Computational Geometry . . . . . . . . . . . . 2-76 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-77 Logical Operator Functions . . . . . . . . . . . . . . . . . . . . . . . . . 2-77 MATLAB Compiler Functions . . . . . . . . . . . . . . . . . . . . . . . 2-78 Matrix and Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . 2-78 Nonlinear Numerical Methods . . . . . . . . . . . . . . . . . . . . . . . 2-82 Polynomial Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-82 Relational Operator Functions . . . . . . . . . . . . . . . . . . . . . . . 2-82 Rounding and Remainder Functions . . . . . . . . . . . . . . . . . . 2-83 Set Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-83 Signal Processing Functions in MATLAB . . . . . . . . . . . . . . 2-84 Signal Processing Toolbox Functions . . . . . . . . . . . . . . . . . . 2-84 Special Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-89 Specialized Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-89 Statistical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-90
vi Contents
String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-90 Structure Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-91 Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-91
System Objects Supported for Code Generation
3
About Code Generation for System Objects . . . . . . . . . . 3-2 Computer Vision System Toolbox System Objects . . . . 3-3 Communications System Toolbox System Objects . . . . 3-7 DSP System Toolbox System Objects . . . . . . . . . . . . . . . . 3-13
Defining MATLAB Variables for C/C++ Code Generation
4
Why Define Variables Differently for Code
Generation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Best Practices for Defining Variables for C/C++ Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Define Variables By Assignment Before Using Them . . . . 4-3 Use Caution When Reassigning Variables . . . . . . . . . . . . . 4-6 Use Type Cast Operators in Variable Definitions . . . . . . . . 4-6 Define Matrices Before Assigning Indexed Variables . . . . . 4-6
When You Can Reassign Variable Properties for C/C++
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Eliminating Redundant Copies of Variables in
Generated Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
vii
When Redundant Copies Occur . . . . . . . . . . . . . . . . . . . . . . 4-8
How to Eliminate Redundant Copies by Defining
Uninitialized Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8 Defining Uninitialized Variables . . . . . . . . . . . . . . . . . . . . . 4-9 Defining and Initializing Persistent Variables . . . . . . . . 4-10
Reusing the Same Variable with Different
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11
When You Can Reuse the Same Variable with Different
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 When You Cannot Reuse Variables . . . . . . . . . . . . . . . . . . . 4-12 Limitations of Variable Reuse . . . . . . . . . . . . . . . . . . . . . . . 4-14 Supported Variable Types . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16
Defining Data for Code Generation
5
How Working with Data is Different for Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Code Generation for Complex Data . . . . . . . . . . . . . . . . . 5-4
Restrictions When Defining Complex Variables . . . . . . . . . 5-4
Expressions Containing Complex Operands Yield Complex
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 Code Generation for Characters . . . . . . . . . . . . . . . . . . . . 5-6
Code Generation for MATLAB Structures
6
How Working with Structures Is Different for Code
Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
viii Contents
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- 1 1 integertypesinmatlab auburn university
- data analysis with matlab cornell university
- chapter 1 introduction to matlab mathworks
- a tutorial on integer programming mathematical and statistical sciences
- symbolic math toolbox quick reference sheet mathworks
- matlab basic functions reference mathworks
- symbolic math toolbox user s guide university of illinois urbana
- matlab text strings miami university
- chapter 1 iteration mathworks
- solving mixed integer linear programs with matlab university of texas