كتاب MATLAB Coder - User's Guide
منتدى هندسة الإنتاج والتصميم الميكانيكى
بسم الله الرحمن الرحيم

أهلا وسهلاً بك زائرنا الكريم
نتمنى أن تقضوا معنا أفضل الأوقات
وتسعدونا بالأراء والمساهمات
إذا كنت أحد أعضائنا يرجى تسجيل الدخول
أو وإذا كانت هذة زيارتك الأولى للمنتدى فنتشرف بإنضمامك لأسرتنا
وهذا شرح لطريقة التسجيل فى المنتدى بالفيديو :
http://www.eng2010.yoo7.com/t5785-topic
وشرح لطريقة التنزيل من المنتدى بالفيديو:
http://www.eng2010.yoo7.com/t2065-topic
إذا واجهتك مشاكل فى التسجيل أو تفعيل حسابك
وإذا نسيت بيانات الدخول للمنتدى
يرجى مراسلتنا على البريد الإلكترونى التالى :

Deabs2010@yahoo.com


-----------------------------------
-Warning-

This website uses cookies
We inform you that this site uses own, technical and third parties cookies to make sure our web page is user-friendly and to guarantee a high functionality of the webpage.
By continuing to browse this website, you declare to accept the use of cookies.
منتدى هندسة الإنتاج والتصميم الميكانيكى
بسم الله الرحمن الرحيم

أهلا وسهلاً بك زائرنا الكريم
نتمنى أن تقضوا معنا أفضل الأوقات
وتسعدونا بالأراء والمساهمات
إذا كنت أحد أعضائنا يرجى تسجيل الدخول
أو وإذا كانت هذة زيارتك الأولى للمنتدى فنتشرف بإنضمامك لأسرتنا
وهذا شرح لطريقة التسجيل فى المنتدى بالفيديو :
http://www.eng2010.yoo7.com/t5785-topic
وشرح لطريقة التنزيل من المنتدى بالفيديو:
http://www.eng2010.yoo7.com/t2065-topic
إذا واجهتك مشاكل فى التسجيل أو تفعيل حسابك
وإذا نسيت بيانات الدخول للمنتدى
يرجى مراسلتنا على البريد الإلكترونى التالى :

Deabs2010@yahoo.com


-----------------------------------
-Warning-

This website uses cookies
We inform you that this site uses own, technical and third parties cookies to make sure our web page is user-friendly and to guarantee a high functionality of the webpage.
By continuing to browse this website, you declare to accept the use of cookies.



 
الرئيسيةالبوابةأحدث الصورالتسجيلدخولحملة فيد واستفيدجروب المنتدى

شاطر
 

 كتاب MATLAB Coder - User's Guide

اذهب الى الأسفل 
كاتب الموضوعرسالة
Admin
مدير المنتدى
مدير المنتدى
Admin

عدد المساهمات : 18996
التقييم : 35494
تاريخ التسجيل : 01/07/2009
الدولة : مصر
العمل : مدير منتدى هندسة الإنتاج والتصميم الميكانيكى

كتاب MATLAB Coder - User's Guide  Empty
مُساهمةموضوع: كتاب MATLAB Coder - User's Guide    كتاب MATLAB Coder - User's Guide  Emptyالإثنين 02 يناير 2023, 4:55 pm

أخواني في الله
أحضرت لكم كتاب
MATLAB Coder - User's Guide
MathWorks

كتاب MATLAB Coder - User's Guide  M_c_u_12
و المحتوى كما يلي :


About MATLAB Coder
1
MATLAB Coder Product Description 1-2
Product Overview 1-3
When to Use MATLAB Coder 1-3
Code Generation for Embedded Software Applications . 1-3
Code Generation for Fixed-Point Algorithms . 1-3
Design Considerations for C/C++ Code Generation
2
When to Generate Code from MATLAB Algorithms 2-2
When Not to Generate Code from MATLAB Algorithms . 2-2
Which Code Generation Feature to Use 2-3
Prerequisites for C/C++ Code Generation from MATLAB . 2-4
MATLAB Code Design Considerations for Code Generation . 2-5
See Also 2-5
Differences Between Generated Code and MATLAB Code . 2-6
Functions that have Multiple Possible Outputs . 2-7
Writing to ans Variable . 2-7
Logical Short-Circuiting 2-7
Loop Index Overflow . 2-8
Indexing for Loops by Using Single Precision Operands 2-9
Index of an Unentered for Loop . 2-10
Character Size 2-11
Order of Evaluation in Expressions . 2-11
Name Resolution While Constructing Function Handles . 2-12
Termination Behavior . 2-13
Size of Variable-Size N-D Arrays . 2-13
Size of Empty Arrays . 2-14
Size of Empty Array That Results from Deleting Elements of an Array . 2-14
Binary Element-Wise Operations with Single and Double Operands . 2-14
Floating-Point Numerical Results 2-15
NaN and Infinity . 2-15
Negative Zero 2-16
Code Generation Target . 2-16
MATLAB Class Property Initialization . 2-16
vii
ContentsMATLAB Classes in Nested Property Assignments That Have Set Methods
. 2-16
MATLAB Handle Class Destructors . 2-17
Variable-Size Data . 2-17
Complex Numbers . 2-17
Converting Strings with Consecutive Unary Operators to double 2-17
Display Function . 2-17
Potential Differences Reporting . 2-20
Addressing Potential Differences Messages 2-20
Disabling and Enabling Potential Differences Reporting for MATLAB Coder
. 2-20
Disabling and Enabling Potential Differences Reporting for Fixed-Point
Designer . 2-21
Potential Differences Messages . 2-22
Automatic Dimension Incompatibility . 2-22
mtimes No Dynamic Scalar Expansion 2-22
Matrix-Matrix Indexing 2-23
Vector-Vector Indexing 2-23
Loop Index Overflow 2-24
MATLAB Language Features Supported for C/C++ Code Generation . 2-26
MATLAB Features That Code Generation Supports . 2-26
MATLAB Language Features That Code Generation Does Not Support 2-27
Functions, Classes, and System Objects Supported for Code
Generation
3
Functions and Objects Supported for C/C++ Code Generation . 3-2
Defining MATLAB Variables for C/C++ Code Generation
4
Variables Definition 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-5
Use Type Cast Operators in Variable Definitions 4-5
Define Matrices Before Assigning Indexed Variables . 4-5
Index Arrays by Using Constant Value Vectors . 4-5
Eliminate Redundant Copies of Variables in Generated Code 4-7
When Redundant Copies Occur . 4-7
How to Eliminate Redundant Copies by Defining Uninitialized Variables
4-7
Defining Uninitialized Variables 4-7
viii ContentsReassignment of Variable Properties 4-9
Reuse the Same Variable with Different Properties . 4-10
When You Can Reuse the Same Variable with Different Properties . 4-10
When You Cannot Reuse Variables . 4-10
Limitations of Variable Reuse . 4-11
Supported Variable Types 4-13
Edit and Represent Coder Type Objects and Properties 4-14
Object Properties 4-14
Legacy Representation of Coder Type Objects 4-15
Defining Data for Code Generation
5
Data Definition Considerations for Code Generation . 5-2
Code Generation for Complex Data . 5-8
Restrictions When Defining Complex Variables . 5-8
Code Generation for Complex Data with Zero-Valued Imaginary Parts 5-8
Results of Expressions That Have Complex Operands . 5-11
Results of Complex Multiplication with Nonfinite Values . 5-11
Encoding of Characters in Code Generation . 5-12
Array Size Restrictions for Code Generation 5-13
Code Generation for Constants in Structures and Arrays 5-14
Code Generation for Strings 5-16
Limitations . 5-16
Differences Between Generated Code and MATLAB Code 5-16
Define String Scalar Inputs 5-17
Define String Scalar Types at the Command Line 5-17
Define String Scalar Inputs in the MATLAB Coder App 5-18
Code Generation for Sparse Matrices 5-19
Sparse Data Types in Generated Code 5-19
Input Definition . 5-19
Code Generation Guidelines 5-20
Code Generation Limitations . 5-21
Specify Array Layout in Functions and Classes . 5-22
Specify Array Layout in a Function . 5-22
Query Array Layout of a Function 5-23
Specify Array Layout in a Class 5-23
Code Design for Row-Major Array Layout . 5-26
Understand Potential Inefficiencies Caused by Array Layout 5-26
Linear Indexing Uses Column-Major Array Layout . 5-28
ixCode Generation for Variable-Size Data
6
Code Generation for Variable-Size Arrays 6-2
Memory Allocation for Variable-Size Arrays . 6-2
Enabling and Disabling Support for Variable-Size Arrays . 6-3
Variable-Size Arrays in a Code Generation Report . 6-3
Control Memory Allocation for Variable-Size Arrays . 6-4
Provide Upper Bounds for Variable-Size Arrays . 6-4
Disable Dynamic Memory Allocation . 6-4
Configure Code Generator to Use Dynamic Memory Allocation for Arrays
Bigger Than a Threshold 6-4
Specify Upper Bounds for Variable-Size Arrays . 6-6
Specify Upper Bounds for Variable-Size Inputs . 6-6
Specify Upper Bounds for Local Variables . 6-6
Define Variable-Size Data for Code Generation . 6-8
Use a Matrix Constructor with Nonconstant Dimensions 6-8
Assign Multiple Sizes to the Same Variable 6-8
Define Variable-Size Data Explicitly by Using coder.varsize 6-9
Diagnose and Fix Variable-Size Data Errors . 6-12
Diagnosing and Fixing Size Mismatch Errors . 6-12
Diagnosing and Fixing Errors in Detecting Upper Bounds 6-14
Incompatibilities with MATLAB in Variable-Size Support for Code
Generation 6-15
Incompatibility with MATLAB for Scalar Expansion . 6-15
Incompatibility with MATLAB in Determining Size of Variable-Size N-D
Arrays 6-16
Incompatibility with MATLAB in Determining Size of Empty Arrays 6-16
Incompatibility with MATLAB in Determining Class of Empty Arrays 6-18
Incompatibility with MATLAB in Matrix-Matrix Indexing . 6-18
Incompatibility with MATLAB in Vector-Vector Indexing . 6-19
Incompatibility with MATLAB in Matrix Indexing Operations for Code
Generation . 6-19
Incompatibility with MATLAB in Concatenating Variable-Size Matrices 6-20
Differences When Curly-Brace Indexing of Variable-Size Cell Array Inside
Concatenation Returns No Elements 6-20
Variable-Sizing Restrictions for Code Generation of Toolbox Functions
. 6-22
Common Restrictions . 6-22
Toolbox Functions with Restrictions for Variable-Size Data . 6-23
Generate Code With Implicit Expansion Enabled . 6-27
Output Size 6-27
Additional Code Generation 6-27
Performance Variation 6-29
x ContentsOptimize Implicit Expansion in Generated Code . 6-31
Disable Implicit Expansion in Specified Function by Using
coder.noImplicitExpansionInFunction . 6-33
Disable Implicit Expansion for Specific Binary Operation by Using
coder.sameSizeBinaryOp 6-34
Disable Implicit Expansion in your Project . 6-35
Representation of Arrays in Generated Code 6-36
Customize Interface Generation . 6-38
Control Memory Allocation for Fixed-Size Arrays . 6-40
Enable Dynamic Memory Allocation for All Fixed-Size Arrays . 6-40
Enable Dynamic Memory Allocation for Arrays Bigger Than a Threshold
. 6-40
Resolve Error: Size Mismatches . 6-42
Issue . 6-42
Possible Solutions 6-42
Code Generation for MATLAB Structures
7
Structure Definition for Code Generation 7-2
Structure Operations Allowed for Code Generation 7-3
Define Scalar Structures for Code Generation 7-4
Restrictions When Defining Scalar Structures by Assignment 7-4
Adding Fields in Consistent Order on Each Control Flow Path 7-4
Restriction on Adding New Fields After First Use . 7-4
Define Arrays of Structures for Code Generation 7-6
Ensuring Consistency of Fields . 7-6
Using repmat to Define an Array of Structures with Consistent Field
Properties 7-6
Defining an Array of Structures by Using struct 7-6
Defining an Array of Structures Using Concatenation 7-7
Index Substructures and Fields 7-8
Assign Values to Structures and Fields . 7-10
Code Generation for Categorical Arrays
8
Code Generation for Categorical Arrays . 8-2
Define Categorical Arrays for Code Generation . 8-2
Allowed Operations on Categorical Arrays 8-2
MATLAB Toolbox Functions That Support Categorical Arrays 8-3
xiDefine Categorical Array Inputs 8-6
Define Categorical Array Inputs at the Command Line . 8-6
Define Categorical Array Inputs in the MATLAB Coder App 8-6
Representation of Categorical Arrays 8-7
Categorical Array Limitations for Code Generation 8-9
Code Generation for Cell Arrays
9
Code Generation for Cell Arrays 9-2
Homogeneous vs. Heterogeneous Cell Arrays 9-2
Controlling Whether a Cell Array Is Homogeneous or Heterogeneous 9-2
Naming the Structure Type That Represents a Heterogeneous Cell Array in
the Generated Code . 9-3
Cell Arrays in Reports 9-3
Control Whether a Cell Array Is Variable-Size 9-5
Define Cell Array Inputs 9-7
Cell Array Limitations for Code Generation 9-8
Cell Array Element Assignment . 9-8
Variable-Size Cell Arrays 9-9
Definition of Variable-Size Cell Array by Using cell 9-9
Cell Array Indexing . 9-12
Growing a Cell Array by Using {end + 1} 9-13
Cell Array Contents 9-14
Passing Cell Arrays to External C/C++ Functions 9-14
Code Generation for Datetime Arrays
10
Code Generation for Datetime Arrays 10-2
Define Datetime Arrays for Code Generation . 10-2
Allowed Operations on Datetime Arrays . 10-2
MATLAB Toolbox Functions That Support Datetime Arrays . 10-2
Define Datetime Array Inputs . 10-5
Define Datetime Array Inputs at the Command Line 10-5
Define Datetime Array Inputs in the MATLAB Coder App 10-5
Representation of Datetime Arrays . 10-6
Datetime Array Limitations for Code Generation . 10-7
xii ContentsCode Generation for Duration Arrays
11
Code Generation for Duration Arrays 11-2
Define Duration Arrays for Code Generation 11-2
Allowed Operations on Duration Arrays . 11-2
MATLAB Toolbox Functions That Support Duration Arrays . 11-3
Define Duration Array Inputs . 11-6
Define Duration Array Inputs at the Command Line 11-6
Define Duration Array Inputs in the MATLAB Coder App . 11-6
Representation of Duration Arrays . 11-7
Duration Array Limitations for Code Generation . 11-8
Code Generation for Tables
12
Code Generation for Tables 12-2
Define Tables for Code Generation . 12-2
Allowed Operations on Tables . 12-2
MATLAB Toolbox Functions That Support Tables 12-3
Define Table Inputs . 12-5
Define Table Inputs at the Command Line 12-5
Define Table Inputs in the MATLAB Coder App 12-5
Representation of Tables 12-6
Table Limitations for Code Generation . 12-8
Creating Tables Limitations 12-8
Modifying Tables Limitations . 12-8
Using Table Functions Limitations 12-10
Code Generation for Timetables
13
Code Generation for Timetables 13-2
Define Timetables for Code Generation 13-2
Allowed Operations on Timetables . 13-2
MATLAB Toolbox Functions That Support Timetables . 13-3
Define Timetable Inputs . 13-6
Define Timetable Inputs at the Command Line 13-6
Define Timetable Inputs in the MATLAB Coder App 13-6
Representation of Timetables . 13-7
Timetable Limitations for Code Generation . 13-9
Creating Timetables Limitations . 13-9
xiiiModifying Timetables Limitations . 13-10
Using Timetable Functions Limitations . 13-12
Code Generation for Enumerated Data
14
Code Generation for Enumerations 14-2
Define Enumerations for Code Generation . 14-2
Allowed Operations on Enumerations . 14-4
MATLAB Toolbox Functions That Support Enumerations . 14-5
Customize Enumerated Types in Generated Code 14-7
Specify a Default Enumeration Value . 14-8
Specify a Header File . 14-8
Include Class Name Prefix in Generated Enumerated Type Value Names
. 14-9
Generate C++11 Code Containing Ordinary C Enumeration . 14-10
Code Generation for MATLAB Classes
15
MATLAB Classes Definition for Code Generation . 15-2
Language Limitations . 15-2
Code Generation Features Not Compatible with Classes . 15-3
Defining Class Properties for Code Generation 15-4
Inheritance from Built-In MATLAB Classes Not Supported . 15-6
Classes That Support Code Generation . 15-7
Generate Code for MATLAB Value Classes 15-8
Generate Code for MATLAB Handle Classes and System Objects . 15-12
Code Generation for Handle Class Destructors . 15-15
Guidelines and Restrictions . 15-15
Behavioral Differences of Objects in Generated Code and in MATLAB 15-16
Class Does Not Have Property . 15-18
Solution 15-18
Passing By Reference Not Supported for Some Properties 15-20
Handle Object Limitations for Code Generation . 15-21
A Variable Outside a Loop Cannot Refer to a Handle Object Allocated Inside
a Loop . 15-21
A Handle Object That a Persistent Variable Refers To Must Be a Singleton
Object . 15-22
References to Handle Objects Can Appear Undefined 15-23
xiv ContentsSystem Objects in MATLAB Code Generation . 15-25
Usage Rules and Limitations for System Objects for Generating Code 15-25
System Objects in codegen 15-27
System Objects in the MATLAB Function Block . 15-27
System Objects in the MATLAB System Block 15-27
System Objects and MATLAB Compiler Software . 15-27
Specify Objects as Inputs at the Command Line 15-28
Consistency Between coder.ClassType Object and Class Definition File
15-29
Limitations for Using Objects as Entry-Point Function Inputs 15-29
Specify Objects as Inputs in the MATLAB Coder App . 15-31
Automatically Define an Object Input Type 15-31
Provide an Example . 15-31
Consistency Between the Type Definition and Class Definition File 15-32
Limitations for Using Objects as Entry-Point Function Inputs 15-32
Work Around Language Limitation: Code Generation Does Not Support
Object Arrays . 15-34
Issue 15-34
Possible Solutions . 15-34
Generating C++ Classes
16
Generate C++ Classes for MATLAB Classes . 16-2
Example: Generate Code for a Handle Class That Has Private and Public
Members 16-2
Additional Usage Notes and Limitations . 16-5
Code Generation for Function Handles
17
Function Handle Limitations for Code Generation 17-2
Code Generation for Deep Learning Arrays
18
Code Generation for dlarray 18-2
Define dlarray for Code Generation 18-2
dlarray Object Functions with Code Generation Support . 18-3
Deep Learning Toolbox Functions with dlarray Code Generation Support
. 18-4
MATLAB Functions with dlarray Code Generation Support . 18-4
xvdlarray Limitations for Code Generation . 18-12
Recommended Usage 18-12
Limitations 18-12
Defining Functions for Code Generation
19
Code Generation for Variable Length Argument Lists . 19-2
Generate Code for arguments Block That Validates Input Arguments
. 19-3
Supported Features 19-3
Input Type Specification and arguments blocks . 19-3
Specify Number of Entry-Point Function Input or Output Arguments to
Generate 19-5
Control Number of Input Arguments 19-5
Control the Number of Output Arguments . 19-6
Code Generation for Anonymous Functions . 19-8
Anonymous Function Limitations for Code Generation 19-8
Code Generation for Nested Functions . 19-9
Nested Function Limitations for Code Generation 19-9
Calling Functions for Code Generation
20
Resolution of Function Calls for Code Generation 20-2
Key Points About Resolving Function Calls . 20-2
Compile Path Search Order 20-2
When to Use the Code Generation Path . 20-2
Resolution of File Types on Code Generation Path 20-4
Compilation Directive %#codegen . 20-5
Use MATLAB Engine to Execute a Function Call in Generated Code . 20-6
When To Declare a Function as Extrinsic 20-6
Use the coder.extrinsic Construct 20-7
Call MATLAB Functions Using feval 20-9
Working with mxArrays . 20-9
Restrictions on Using Extrinsic Functions . 20-11
Code Generation for Recursive Functions 20-12
Compile-Time Recursion 20-12
Run-Time Recursion . 20-13
Disallow Recursion 20-13
Disable Run-Time Recursion . 20-13
xvi ContentsRecursive Function Limitations for Code Generation . 20-14
Force Code Generator to Use Run-Time Recursion . 20-15
Treat the Input to the Recursive Function as a Nonconstant . 20-15
Make the Input to the Recursive Function Variable-Size 20-16
Assign Output Variable Before the Recursive Call . 20-17
Avoid Duplicate Functions in Generated Code 20-18
Issue 20-18
Cause 20-18
Solution 20-18
Fixed-Point Conversion
21
Detect Unexecuted and Constant-Folded Code . 21-2
What Is Unexecuted Code? . 21-2
Detect Unexecuted Code 21-2
Fix Unexecuted Code . 21-3
Convert MATLAB Code to Fixed-Point C Code . 21-5
Propose Fixed-Point Data Types Based on Simulation Ranges 21-6
Propose Fixed-Point Data Types Based on Derived Ranges 21-17
Specify Type Proposal Options . 21-29
Detect Overflows 21-32
Replace the exp Function with a Lookup Table 21-40
Replace a Custom Function with a Lookup Table 21-47
Enable Plotting Using the Simulation Data Inspector 21-53
Visualize Differences Between Floating-Point and Fixed-Point Results
21-54
View and Modify Variable Information 21-64
View Variable Information 21-64
Modify Variable Information . 21-64
Revert Changes 21-65
Promote Sim Min and Sim Max Values . 21-65
Automated Fixed-Point Conversion . 21-67
Automated Fixed-Point Conversion Capabilities 21-67
Code Coverage . 21-67
Proposing Data Types 21-70
Locking Proposed Data Types 21-73
Viewing Functions 21-73
Viewing Variables . 21-80
xviiLog Data for Histogram 21-82
Function Replacements 21-84
Validating Types 21-84
Testing Numerics . 21-85
Detecting Overflows . 21-85
Convert Fixed-Point Conversion Project to MATLAB Scripts . 21-86
Generated Fixed-Point Code . 21-88
Location of Generated Fixed-Point Files 21-88
Minimizing fi-casts to Improve Code Readability 21-88
Avoiding Overflows in the Generated Fixed-Point Code . 21-89
Controlling Bit Growth . 21-89
Avoiding Loss of Range or Precision . 21-90
Handling Non-Constant mpower Exponents . 21-91
Fixed-Point Code for MATLAB Classes 21-93
Automated Conversion Support for MATLAB Classes 21-93
Unsupported Constructs 21-93
Coding Style Best Practices . 21-93
Automated Fixed-Point Conversion Best Practices . 21-95
Create a Test File . 21-95
Prepare Your Algorithm for Code Acceleration or Code Generation 21-96
Check for Fixed-Point Support for Functions Used in Your Algorithm 21-96
Manage Data Types and Control Bit Growth . 21-97
Convert to Fixed Point . 21-97
Use the Histogram to Fine-Tune Data Type Settings . 21-98
Optimize Your Algorithm . 21-98
Avoid Explicit Double and Single Casts 21-100
Replacing Functions Using Lookup Table Approximations . 21-101
MATLAB Language Features Supported for Automated Fixed-Point
Conversion 21-102
MATLAB Language Features Supported for Automated Fixed-Point
Conversion . 21-102
MATLAB Language Features Not Supported for Automated Fixed-Point
Conversion . 21-103
Inspecting Data Using the Simulation Data Inspector 21-104
What Is the Simulation Data Inspector? . 21-104
Import Logged Data 21-104
Export Logged Data 21-104
Group Signals 21-104
Run Options 21-104
Create Report 21-105
Comparison Options 21-105
Enabling Plotting Using the Simulation Data Inspector 21-105
Save and Load Simulation Data Inspector Sessions . 21-105
Custom Plot Functions 21-106
Data Type Issues in Generated Code . 21-107
Enable the Highlight Option in the MATLAB Coder App . 21-107
xviii ContentsEnable the Highlight Option at the Command Line . 21-107
Stowaway Doubles . 21-107
Stowaway Singles 21-107
Expensive Fixed-Point Operations 21-107
Automated Fixed-Point Conversion Using Programmatic
Workflow
22
Convert MATLAB Code to Fixed-Point C Code . 22-2
Propose Fixed-Point Data Types Based on Simulation Ranges 22-4
Propose Fixed-Point Data Types Based on Derived Ranges . 22-9
Detect Overflows 22-16
Replace the exp Function with a Lookup Table 22-19
Replace a Custom Function with a Lookup Table 22-21
Enable Plotting Using the Simulation Data Inspector 22-23
Visualize Differences Between Floating-Point and Fixed-Point Results
22-24
Single-Precision Conversion
23
Generate Single-Precision C Code at the Command Line 23-2
Prerequisites . 23-2
Create a Folder and Copy Relevant Files . 23-2
Determine the Type of the Input Argument . 23-4
Generate and Run Single-Precision MEX to Verify Numerical Behavior
. 23-4
Generate Single-Precision C Code 23-4
View the Generated Single-Precision C Code . 23-4
View Potential Data Type Issues . 23-5
Generate Single-Precision C Code Using the MATLAB Coder App . 23-6
Prerequisites . 23-6
Create a Folder and Copy Relevant Files . 23-6
Open the MATLAB Coder App . 23-8
Select the Source Files 23-8
Enable Single-Precision Conversion 23-8
Define Input Types . 23-9
Check for Run-Time Issues . 23-9
Generate Single-Precision C Code 23-10
xixView the Generated C Code . 23-10
View Potential Data Type Issues 23-10
Generate Single-Precision MATLAB Code 23-11
Prerequisites 23-11
Create a Folder and Copy Relevant Files 23-11
Set Up the Single-Precision Configuration Object . 23-12
Generate Single-Precision MATLAB Code . 23-13
View the Type Proposal Report . 23-13
View Generated Single-Precision MATLAB Code 23-14
View Potential Data Type Issues 23-14
Compare the Double-Precision and Single-Precision Variables . 23-15
Optionally Generate Single-Precision C Code 23-16
Choose a Single-Precision Conversion Workflow 23-18
Single-Precision Conversion Best Practices 23-19
Use Integers for Index Variables 23-19
Limit Use of assert Statements . 23-19
Initialize MATLAB Class Properties in Constructor 23-19
Provide a Test File That Calls Your MATLAB Function 23-19
Prepare Your Code for Code Generation 23-20
Verify Double-Precision Code Before Single-Precision Conversion . 23-20
Best Practices for Generation of Single-Precision C/C++ Code . 23-20
Best Practices for Generation of Single-Precision MATLAB Code 23-21
Warnings from Conversion to Single-Precision C/C++ Code . 23-22
Function Uses Double-Precision in the C89/C90 Standard . 23-22
Built-In Function Is Implemented in Double-Precision 23-22
Built-In Function Returns Double-Precision . 23-23
Combining Integers and Double-Precision Numbers . 23-24
MATLAB Language Features Supported for Single-Precision Conversion
23-25
MATLAB Language Features Supported for Single-Precision Conversion
23-25
MATLAB Language Features Not Supported for Single-Precision Conversion
23-26
Setting Up a MATLAB Coder Project
24
Set Up a MATLAB Coder Project 24-2
Create a Project . 24-2
Open an Existing Project 24-2
Specify Properties of Entry-Point Function Inputs Using the App . 24-3
Why Specify Input Properties? 24-3
Specify an Input Definition Using the App 24-3
Automatically Define Input Types by Using the App . 24-4
xx ContentsMake Dimensions Variable-Size When They Meet Size Threshold . 24-5
Define Input Parameter by Example by Using the App . 24-6
Define an Input Parameter by Example 24-6
Specify Input Parameters by Example . 24-7
Specify a String Scalar Input Parameter by Example 24-8
Specify a Structure Type Input Parameter by Example 24-8
Specify a Cell Array Type Input Parameter by Example 24-9
Specify an Enumerated Type Input Parameter by Example 24-10
Specify an Object Input Type Parameter by Example 24-11
Specify a Fixed-Point Input Parameter by Example 24-12
Specify an Input from an Entry-Point Function Output Type . 24-13
Define or Edit Input Parameter Type by Using the App . 24-14
Define or Edit an Input Parameter Type 24-14
Specify a String Scalar Input Parameter 24-15
Specify an Enumerated Type Input Parameter . 24-15
Specify a Fixed-Point Input Parameter . 24-16
Specify a Structure Input Parameter . 24-16
Specify a Cell Array Input Parameter 24-18
Define Constant Input Parameters Using the App . 24-23
Define Inputs Programmatically in the MATLAB File 24-24
Add Global Variables by Using the App 24-25
Specify Global Variable Type and Initial Value Using the App 24-26
Why Specify a Type Definition for Global Variables? . 24-26
Specify a Global Variable Type . 24-26
Define a Global Variable by Example . 24-26
Define or Edit Global Variable Type . 24-27
Define Global Variable Initial Value 24-27
Define Global Variable Constant Value . 24-28
Remove Global Variables . 24-28
Undo and Redo Changes to Type Definitions in the App 24-29
Code Generation Readiness Screening in the MATLAB Coder App 24-30
Slow Operations in MATLAB Coder App . 24-31
Unable to Open a MATLAB Coder Project 24-32
Preparing MATLAB Code for C/C++ Code Generation
25
Workflow for Preparing MATLAB Code for Code Generation 25-2
See Also . 25-2
Fixing Errors Detected at Design Time . 25-3
See Also . 25-3
xxiUsing the Code Analyzer . 25-4
Check Code with the Code Analyzer 25-5
Check Code by Using the Code Generation Readiness Tool . 25-7
Run Code Generation Readiness Tool at the Command Line 25-7
Run Code Generation Readiness Tool from the Current Folder Browser
. 25-7
Run the Code Generation Readiness Tool Using the MATLAB Coder App
. 25-7
Code Generation Readiness Tool 25-8
Issues Tab . 25-8
Files Tab . 25-9
Unable to Determine Code Generation Readiness . 25-11
Generate MEX Functions by Using the MATLAB Coder App . 25-12
Workflow for Generating MEX Functions Using the MATLAB Coder App
25-12
Generate a MEX Function Using the MATLAB Coder App . 25-12
Configure Project Settings 25-14
Build a MATLAB Coder Project . 25-14
See Also 25-15
Generate MEX Functions at the Command Line . 25-16
Command-line Workflow for Generating MEX Functions 25-16
Generate a MEX Function at the Command Line 25-16
Fix Errors Detected at Code Generation Time 25-17
See Also 25-17
Running and Debugging MEX Functions 25-18
Debug MEX Functions . 25-18
Debug MEX Functions by Using a C/C++ Debugger . 25-18
Debugging Strategies 25-19
Collect and View Line Execution Counts for Your MATLAB Code . 25-20
Resolve Error: Function Is Not Supported for Code Generation 25-23
Issue 25-23
Possible Solutions . 25-23
Debug Generated C/C++ Code . 25-25
Testing MEX Functions in MATLAB
26
Why Test MEX Functions in MATLAB? 26-2
xxii ContentsWorkflow for Testing MEX Functions in MATLAB . 26-3
See Also . 26-3
Running MEX Functions . 26-4
Debug MEX Functions 26-4
Debug MEX Functions by Using a C/C++ Debugger 26-4
Check for Run-Time Issues by Using the App 26-5
Collect MATLAB Line Execution Counts . 26-5
Disable JIT Compilation for Parallel Loops . 26-5
Verify MEX Functions in the MATLAB Coder App . 26-7
Verify MEX Functions at the Command Line . 26-8
Debug Run-Time Errors 26-9
Viewing Errors in the Run-Time Stack . 26-9
Handling Run-Time Errors 26-10
Using MEX Functions That MATLAB Coder Generates . 26-11
Generating C/C++ Code from MATLAB Code
27
Code Generation Workflow . 27-3
See Also . 27-3
Generating Standalone C/C++ Executables from MATLAB Code 27-4
Generate a C Executable Using the MATLAB Coder App . 27-4
Generate a C Executable at the Command Line 27-10
Specifying main Functions for C/C++ Executables 27-11
Specify main Functions 27-12
Configure Build Settings 27-13
Specify Build Type 27-13
Specify a Language for Code Generation . 27-15
Specify Output File Name . 27-16
Specify Output File Locations 27-16
Parameter Specification Methods . 27-17
Specify Build Configuration Parameters 27-17
Specify Configuration Parameters in Command-Line Workflow
Interactively 27-22
Create and Modify Configuration Objects by Using the Dialog Box 27-22
Additional Functionalities in the Dialog Box . 27-22
Specify Data Types Used in Generated Code 27-25
Specify Data Type Using the MATLAB Coder App . 27-25
Specify Data Type at the Command Line 27-25
Use Generated Initialize and Terminate Functions 27-26
Initialize Function 27-26
xxiiiTerminate Function . 27-28
Change the Language Standard 27-30
Convert codegen Command to Equivalent MATLAB Coder Project 27-31
Example: Convert a Complete codegen Command to a Project File 27-31
Example: Convert an Incomplete codegen Command to a Template Project
File . 27-32
Limitations 27-32
Share Build Configuration Settings . 27-34
Export Settings 27-34
Import Settings 27-35
Convert MATLAB Coder Project to MATLAB Script 27-36
Convert a Project Using the MATLAB Coder App . 27-36
Convert a Project Using the Command-Line Interface 27-36
Run the Script . 27-36
Special Cases That Generate Additional MAT-File . 27-37
Preserve Variable Names in Generated Code . 27-39
Reserved Keywords 27-40
C Reserved Keywords 27-40
C++ Reserved Keywords . 27-40
Keywords Reserved for Code Generation . 27-41
Reserved Prefixes . 27-42
MATLAB Coder Code Replacement Library Keywords 27-42
Specify Properties of Entry-Point Function Inputs . 27-44
Why You Must Specify Input Properties 27-44
Properties to Specify 27-44
Rules for Specifying Properties of Primary Inputs . 27-47
Methods for Defining Properties of Primary Inputs 27-47
Define Input Properties by Example at the Command Line 27-48
Specify Constant Inputs at the Command Line . 27-50
Specify Variable-Size Inputs at the Command Line 27-51
Input Type Specification and arguments blocks 27-52
Specify Cell Array Inputs at the Command Line . 27-54
Specify Cell Array Inputs by Example 27-54
Specify the Type of the Cell Array Input 27-55
Make a Homogeneous Copy of a Type 27-55
Make a Heterogeneous Copy of a Type . 27-56
Specify Variable-Size Cell Array Inputs . 27-57
Specify Type Name for Heterogeneous Cell Array Inputs . 27-58
Specify Constant Cell Array Inputs 27-58
Constant Input Checking in MEX Functions 27-59
Control Whether a MEX Function Checks the Value of a Constant Input
27-60
Define Input Properties Programmatically in the MATLAB File 27-63
How to Use assert with MATLAB Coder 27-63
Rules for Using assert Function 27-67
xxiv ContentsSpecifying General Properties of Primary Inputs 27-68
Specifying Properties of Primary Fixed-Point Inputs . 27-69
Specifying Properties of Cell Arrays . 27-69
Specifying Class and Size of Scalar Structure 27-70
Specifying Class and Size of Structure Array 27-71
Create and Edit Input Types by Using the Coder Type Editor 27-72
Open the Coder Type Editor . 27-72
Common Editor Actions 27-72
Type Browser Pane 27-73
Type Properties Pane 27-74
MATLAB Code Pane . 27-75
Speed Up Compilation by Generating Only Code 27-77
Disable Creation of the Code Generation Report 27-78
Paths and File Infrastructure Setup 27-79
Compile Path Search Order . 27-79
Specify Folders to Search for Custom Code 27-79
Naming Conventions 27-79
Generate Code for Multiple Entry-Point Functions 27-81
Generating Code for Multiple Entry-Point Functions . 27-81
Call a Single Entry-Point Function from a MEX Function . 27-82
Generate Code for More Than One Entry-Point Function Using the MATLAB
Coder App 27-82
Generate One MEX Function for Multiple Signatures 27-85
Generate Multisignature MEX Function for a Single Entry-Point Function
27-85
Generate Multisignature MEX Function for Multiple Entry-Point Functions
27-86
Pass an Entry-Point Function Output as an Input . 27-88
Pass an Entry-Point Function Output as an Input to Another Entry-Point
Function 27-88
Use coder.OutputType to Facilitate Code Componentization . 27-89
Generate Code for Global Data . 27-91
Workflow . 27-91
Declare Global Variables 27-91
Define Global Data 27-91
Synchronizing Global Data with MATLAB . 27-93
Define Constant Global Data . 27-95
Global Data Limitations for Generated Code . 27-97
Specify Global Cell Arrays at the Command Line 27-99
Generate Code for Enumerations 27-100
Generate Code for Variable-Size Data 27-101
Disable Support for Variable-Size Data 27-101
Control Dynamic Memory Allocation 27-101
Generating Code for MATLAB Functions with Variable-Size Data 27-103
xxvGenerate Code for a MATLAB Function That Expands a Vector in a Loop
. 27-104
How MATLAB Coder Partitions Generated Code . 27-109
Partitioning Generated Files 27-109
How to Select the File Partitioning Method . 27-109
Partitioning Generated Files with One C/C++ File Per MATLAB File 27-109
Generated Files and Locations 27-113
File Partitioning and Inlining . 27-115
Requirements for Signed Integer Representation 27-118
Build Process Customization . 27-119
RTW.BuildInfo Methods . 27-119
coder.updateBuildInfo Function . 27-120
coder.ExternalDependency Class 27-120
Post-Code-Generation Command 27-120
Run-time Stack Overflow 27-122
Compiler and Linker Errors 27-123
Failure to Specify a Main Function . 27-123
Failure to Specify External Code Files 27-123
Errors Caused by External Code . 27-124
Pass Structure Arguments by Reference or by Value in Generated Code
. 27-125
Name the C Structure Type to Use With a Global Structure Variable 27-132
Generate Code for an LED Control Function That Uses Enumerated Types
. 27-134
Generate Code That Uses N-Dimensional Indexing . 27-137
Improve Readability with N-Dimensional Indexing and Row-Major Layout
. 27-137
Column-Major Layout and N-Dimensional Indexing . 27-138
Other Code Generation Considerations 27-139
Install OpenMP Library on macOS Platform . 27-141
Generate Code to Detect Edges on Images 27-142
C Code Generation for a MATLAB Kalman Filtering Algorithm . 27-148
Generate Code to Optimize Portfolio by Using Black Litterman Approach
. 27-157
Generate Code for Persistent Variables . 27-167
Generate Code for Structure Arrays . 27-171
Add Custom Toolchains to MATLAB® Coder™ Build Process . 27-173
xxvi ContentsGenerate Code for Sobel Edge Detection That Uses Half-Precision Data
Type . 27-182
Build Process Support for File and Folder Names . 28-25
Filenames with Spaces . 28-25
Folder Names with Spaces 28-25
Troubleshooting Errors When Folder Names Have Spaces 28-27
Folder Names with Special Characters . 28-28
Very Long Folder Paths . 28-28
Generate Code That Reads Data from a File 28-29
Verify Generated C/C++ Code
29
Tracing Generated C/C++ Code to MATLAB Source Code 29-2
Generate Traceability Tags . 29-2
Format of Traceability Tags 29-2
Location of Comments in Generated Code 29-2
Traceability Tag Limitations 29-6
Code Generation Reports 29-7
Report Generation . 29-7
Report Location . 29-8
Errors and Warnings 29-8
Files and Functions 29-8
MATLAB Source . 29-9
MATLAB Variables 29-10
Tracing Code 29-11
Code Insights 29-11
Additional Reports 29-12
Report Limitations 29-12
Access Code Generation Report Information Programmatically 29-13
Create Report Information Object . 29-13
Example: Create Report Information Object for Successful Code Generation
29-13
Example: Create Report Information Object for Successful Code Generation
That Checks Out Toolbox Licenses 29-16
Example: Create Report Information Object for Failed Code Generation
29-17
Inspect Code Manually . 29-18
Transferring Code Configuration Objects to a New MATLAB Session 29-19
Generate Standalone C/C++ Code That Detects and Reports Run-Time
Errors . 29-20
Generated C Code vs. Generated C++ Code . 29-20
Example: Compare Generated C and C++ Code That Include Run-Time
Checks . 29-20
Limitations 29-23
xxviiExample: Generate Standalone C Code That Detects and Reports RunTime Errors 29-25
Testing Code Generated from MATLAB Code . 29-27
Unit Test Generated Code with MATLAB Coder . 29-28
Unit Test External C Code with MATLAB Coder . 29-34
Calculate Number of Lines of Code by Using Report Information Object
29-44
Code Replacement for MATLAB Code
30
What Is Code Replacement? 30-2
Code Replacement Libraries 30-2
Code Replacement Terminology . 30-4
Code Replacement Limitations 30-5
Choose a Code Replacement Library . 30-6
About Choosing a Code Replacement Library . 30-6
Explore Available Code Replacement Libraries 30-6
Explore Code Replacement Library Contents . 30-6
Replace Code Generated from MATLAB Code 30-8
Generate SIMD Code for MATLAB Functions . 30-10
MATLAB Functions That Support SIMD Code 30-10
Generate SIMD Code Versus Plain C Code 30-12
Limitations 30-14
Custom Toolchain Registration
31
Custom Toolchain Registration . 31-2
What Is a Custom Toolchain? . 31-2
What Is a Factory Toolchain? . 31-2
What is a Toolchain Definition? 31-2
Key Terms . 31-3
Typical Workflow 31-3
About coder.make.ToolchainInfo 31-5
Create and Edit Toolchain Definition File . 31-7
Toolchain Definition File with Commentary . 31-8
Steps Involved in Writing a Toolchain Definition File 31-8
Write a Function That Creates a ToolchainInfo Object . 31-8
xxviii ContentsSetup . 31-9
Macros 31-9
C Compiler . 31-9
C++ Compiler . 31-10
Linker . 31-10
Archiver 31-11
Builder . 31-11
Build Configurations . 31-11
Create and Validate ToolchainInfo Object 31-13
Register the Custom Toolchain 31-14
Use the Custom Toolchain 31-16
Troubleshooting Custom Toolchain Validation 31-17
Build Tool Command Path Incorrect . 31-17
Build Tool Not in System Path 31-17
Tool Path Does Not Exist 31-18
Path Incompatible with Builder or Build Tool 31-18
Unsupported Platform . 31-18
Toolchain is Not installed . 31-18
Project or Configuration Is Using the Template Makefile 31-19
Prevent Circular Data Dependencies with One-Pass or Single-Pass Linkers
31-20
Build 32-bit DLL on 64-bit Windows® Platform Using MSVC Toolchain
31-21
Deploying Generated Code
32
C Compiler Considerations for Signed Integer Overflows 32-2
Use C Arrays in the Generated Function Interfaces . 32-3
Implementation of Arrays in the Generated C/C++ Code 32-3
The emxArray Dynamic Data Structure Definition 32-4
Utility Functions for Interacting with emxArray Data . 32-5
Examples 32-6
Use Dynamically Allocated C++ Arrays in Generated Function Interfaces
32-15
Using the coder::array Class Template . 32-15
Examples . 32-16
Change Interface Generation 32-19
Use a Dynamic Library in a Microsoft Visual Studio Project . 32-20
Incorporate Generated Code Using an Example Main Function 32-23
Workflow for Using an Example Main Function . 32-23
Control Example Main Generation Using the MATLAB Coder App . 32-23
xxixControl Example Main Generation Using the Command-Line Interface
32-24
Use an Example C Main in an Application 32-25
Prerequisites 32-25
Create a Folder and Copy Relevant Files 32-25
Run the Sobel Filter on the Image 32-27
Generate and Test a MEX Function 32-29
Generate an Example Main Function for sobel.m . 32-29
Copy the Example Main Files 32-32
Modify the Generated Example Main Function . 32-32
Generate the Sobel Filter Application 32-40
Run the Sobel Filter Application 32-41
Display the Resulting Image . 32-41
Package Code for Other Development Environments . 32-42
When to Package Code . 32-42
Package Generated Code Using the MATLAB Coder App 32-42
Package Generated Code at the Command Line 32-43
Specify packNGo Options . 32-44
Structure of Generated Example C/C++ Main Function 32-46
Contents of the File main.c or main.cpp 32-46
Contents of the File main.h 32-48
Troubleshoot Failures in Deployed Code . 32-50
Using Dynamic Memory Allocation for an Atoms Simulation 32-51
Register New Hardware Devices . 32-56
Specify Hardware Implementation for New Device 32-56
Specify Hardware Implementation That Persists Over MATLAB Sessions
32-57
Create Hardware Implementation by Modifying Existing Implementation
32-57
Create Hardware Implementation by Reusing Existing Implementation
32-57
Validate Hardware Device Data 32-58
Export Hardware Device Data . 32-59
Create Alternative Identifier for Target Object . 32-59
Upgrade Data Definitions for Hardware Devices 32-60
Configure CMake Build Process 32-62
Specify CMake Toolchain Definition . 32-62
Available CMake Toolchain Definitions . 32-63
Create Custom CMake Toolchain Definition 32-65
Deploy Generated C Code to External Hardware: Raspberry Pi Examples
32-68
Prerequisites 32-68
Hardware Implementation Parameters . 32-69
Hello World Example 32-70
Spring Mass Damper System Example . 32-71
xxx ContentsDeploy Generated Code . 32-75
Main Function . 32-75
Generated Function Interfaces . 32-75
Executable Applications 32-76
Static and Dynamic Libraries 32-77
Generated File Structure . 32-77
Code Verification . 32-78
Custom Hardware Considerations 32-78
Other Deployment Strategies 32-78
Approaches for Building Code Generated from MATLAB Code . 32-79
Accelerating MATLAB Algorithms
33
Workflow for Accelerating MATLAB Algorithms 33-2
See Also . 33-2
Best Practices for Using MEX Functions to Accelerate MATLAB
Algorithms 33-3
Accelerate Code That Dominates Execution Time 33-3
Include Loops Inside MEX Function 33-3
Avoid Generating MEX Functions from Unsupported Functions . 33-4
Avoid Generating MEX Functions if Built-In MATLAB Functions Dominate
Run Time 33-4
Minimize MEX Function Calls . 33-4
Accelerate MATLAB Algorithms . 33-6
Modifying MATLAB Code for Acceleration 33-7
How to Modify Your MATLAB Code for Acceleration 33-7
Profile MEX Functions by Using MATLAB Profiler 33-8
MEX Profile Generation . 33-8
Example . 33-8
Effect of Folding Expressions on MEX Code Coverage . 33-11
Control Run-Time Checks . 33-12
Types of Run-Time Checks 33-12
When to Disable Run-Time Checks 33-12
How to Disable Run-Time Checks . 33-13
Algorithm Acceleration Using Parallel for-Loops (parfor) . 33-14
Parallel for-Loops (parfor) in Generated Code 33-14
How parfor-Loops Improve Execution Speed . 33-14
When to Use parfor-Loops 33-15
When Not to Use parfor-Loops . 33-15
parfor-Loop Syntax 33-15
parfor Restrictions 33-16
Control Compilation of parfor-Loops 33-18
When to Disable parfor . 33-18
xxxiReduction Assignments in parfor-Loops . 33-19
What are Reduction Assignments? 33-19
Multiple Reductions in a parfor-Loop 33-19
Classification of Variables in parfor-Loops . 33-20
Overview . 33-20
Sliced Variables 33-21
Broadcast Variables . 33-22
Reduction Variables . 33-22
Temporary Variables . 33-27
Accelerate MATLAB Algorithms That Use Parallel for-Loops (parfor)
33-29
Specify Maximum Number of Threads in parfor-Loops . 33-30
Troubleshooting parfor-Loops . 33-31
Global or Persistent Declarations in parfor-Loop 33-31
Compiler Does Not Support OpenMP 33-31
Generate MEX Code to Accelerate Simulation of Bouncing Balls . 33-32
Generate MEX Code to Calculate Geodesics in Curved Space-Time . 33-36
Generate Accelerated MEX Code for Reverberation Using MATLAB
Classes 33-40
Using PARFOR to Speed Up an Image Contrast Enhancement Algorithm
33-42
Use Generated Code to Accelerate an Application Deployed with MATLAB
Compiler . 33-51
External Code Integration
34
Call Custom C/C++ Code from the Generated Code . 34-2
Call C Code 34-2
Return Multiple Values from a C Function 34-3
Pass Data by Reference . 34-4
Integrate External Code that Uses Custom Data Types 34-5
Integrate External Code that Uses Pointers, Structures, and Arrays 34-6
Configure Build for External C/C++ Code . 34-9
Provide External Files for Code Generation 34-9
Configure Build from Within a Function . 34-9
Configure Build by Using the Configuration Object 34-10
Configure Build by Using the MATLAB Coder App 34-11
Develop Interface for External C/C++ Code 34-12
Create a class from coder.ExternalDependency . 34-12
Best Practices for Using coder.ExternalDependency . 34-13
xxxii ContentsMapping MATLAB Types to Types in Generated Code 34-15
Complex Types . 34-16
Structure Types 34-16
Fixed-Point Types . 34-16
Character Vectors . 34-17
Multiword Types . 34-17
Generate Code to Read a Text File 34-19
Generate C/C++ Strings from MATLAB Strings and Character Row
Vectors 34-27
Add New Line to Strings in Generated Code . 34-27
Limitations 34-28
Generate Efficient and Reusable Code
35
Optimization Strategies . 35-3
Modularize MATLAB Code . 35-5
Avoid Data Copies of Function Inputs in Generated Code 35-6
Inline Code 35-8
Control Inlining to Fine-Tune Performance and Readability of Generated
Code . 35-9
Control Inlining of a Specific MATLAB Function . 35-9
Control Inlining by Using Code Generation Settings 35-9
Interaction Between Different Inlining Controls 35-11
Example: Control Inlining at the Boundary Between Your Functions and
MathWorks® Functions 35-11
Fold Function Calls into Constants . 35-14
Control Stack Space Usage 35-15
Stack Allocation and Performance 35-18
Allocate Heap Space from Command Line 35-18
Allocate Heap Space Using the MATLAB Coder App . 35-18
Dynamic Memory Allocation and Performance 35-19
When Dynamic Memory Allocation Occurs 35-19
Minimize Dynamic Memory Allocation 35-20
Provide Maximum Size for Variable-Size Arrays . 35-21
Disable Dynamic Memory Allocation During Code Generation . 35-25
xxxiiiSet Dynamic Memory Allocation Threshold 35-26
Set Dynamic Memory Allocation Threshold Using the MATLAB Coder App
35-26
Set Dynamic Memory Allocation Threshold at the Command Line . 35-26
Optimize Dynamic Array Access 35-28
Disable Cache Dynamic Array Data Pointer Property 35-28
Compare Generated C Code . 35-28
Excluding Unused Paths from Generated Code . 35-30
Prevent Code Generation for Unused Execution Paths . 35-31
Prevent Code Generation When Local Variable Controls Flow 35-31
Prevent Code Generation When Input Variable Controls Flow 35-31
Generate Code with Parallel for-Loops (parfor) . 35-33
Minimize Redundant Operations in Loops . 35-34
Unroll for-Loops and parfor-Loops 35-35
Force for-Loop Unrolling by Using coder.unroll . 35-35
Set Loop Unrolling Threshold for All for-Loops and parfor-Loops in the
MATLAB Code . 35-36
Disable Support for Integer Overflow or Nonfinites 35-40
Disable Support for Integer Overflow 35-40
Disable Support for Nonfinite Numbers 35-40
Integrate External/Custom Code . 35-42
MATLAB Coder Optimizations in Generated Code . 35-46
Constant Folding . 35-46
Loop Fusion . 35-47
Successive Matrix Operations Combined . 35-47
Unreachable Code Elimination . 35-47
memcpy Calls 35-48
memset Calls 35-48
Use coder.const with Extrinsic Function Calls 35-49
Reduce Code Generation Time by Using coder.const with feval . 35-49
Force Constant-Folding by Using coder.const with feval 35-49
memcpy Optimization 35-51
memset Optimization 35-52
Reuse Large Arrays and Structures . 35-53
LAPACK Calls in Generated Code . 35-54
Speed Up Linear Algebra in Generated Standalone Code by Using LAPACK
Calls 35-55
Specify LAPACK Library 35-55
Write LAPACK Callback Class 35-55
Generate LAPACK Calls by Specifying a LAPACK Callback Class 35-56
xxxiv ContentsLocate LAPACK Library in Execution Environment 35-57
BLAS Calls in Generated Code . 35-58
Speed Up Matrix Operations in Generated Standalone Code by Using
BLAS Calls . 35-59
Specify BLAS Library 35-59
Write BLAS Callback Class 35-59
Generate BLAS Calls by Specifying a BLAS Callback Class 35-61
Locate BLAS Library in Execution Environment 35-61
Usage Notes and Limitations for OpenBLAS Library . 35-61
Speed Up Fast Fourier Transforms in Generated Standalone Code by
Using FFTW Library Calls . 35-63
FFTW Planning Considerations . 35-63
Install FFTW Library 35-63
Write an FFT Callback Class . 35-64
Generate FFTW Library Calls by Specifying an FFT Library Callback Class
35-65
Synchronize Multithreaded Access to FFTW Planning in Generated
Standalone Code 35-67
Prerequisites 35-67
Create a MATLAB Function . 35-67
Write Supporting C Code . 35-68
Write an FFT Library Callback Class . 35-68
Generate a Dynamically Linked Library 35-69
Specify Configuration Parameters in the MATLAB Coder App 35-70
Speed Up MEX Generation by Using JIT Compilation 35-71
Specify Use of JIT Compilation in the MATLAB Coder App 35-71
Specify Use of JIT Compilation at the Command Line 35-71
JIT Compilation Incompatibilities . 35-71
Automatically Parallelize for Loops in Generated Code . 35-73
Parallelize for Loops by Using MATLAB Coder App 35-73
Parallelize for Loops at Command Line . 35-73
Inspect Generated Code and Code Insights 35-74
Disable Automatic Parallelization of a for Loop . 35-75
Parallelize Implicit for Loops 35-75
Parallelize for Loops Performing Reduction Operations . 35-76
Usage Notes and Limitations 35-77
Specify Maximum Number of Threads to Run Parallel for-Loops in the
Generated Code . 35-79
Specify Number of Threads by Using MATLAB Coder App 35-79
Specify Number of Threads at the Command Line . 35-80
Create Custom Hardware Processor . 35-81
Optimize Generated Code for Fast Fourier Transform Functions . 35-83
Intel Target Support . 35-83
ARM Target Support . 35-84
MEX Target Support . 35-85
xxxvGenerating Reentrant C Code from MATLAB Code
36
Generate Reentrant C Code from MATLAB Code . 36-2
About This Tutorial . 36-2
Copying Files Locally . 36-3
About the Example . 36-3
Providing a C main Function 36-4
Configuring Build Parameters . 36-6
Generating the C Code 36-6
Viewing the Generated C Code 36-6
Running the Code 36-7
Key Points to Remember . 36-7
Learn More 36-8
Reentrant Code 36-9
Specify Generation of Reentrant Code 36-11
Specify Generation of Reentrant Code Using the MATLAB Coder App 36-11
Specify Generation of Reentrant Code Using the Command-Line Interface
36-11
API for Generated Reusable Code 36-12
Call Reentrant Code in a Single-Threaded Environment 36-13
Call Reentrant Code in a Multithreaded Environment 36-14
Multithreaded Examples 36-14
Call Reentrant Code with No Persistent or Global Data (UNIX Only) 36-15
Provide a Main Function 36-15
Generate Reentrant C Code . 36-17
Examine the Generated Code 36-17
Run the Code 36-18
Call Reentrant Code — Multithreaded with Persistent Data (Windows
Only) 36-19
MATLAB Code for This Example 36-19
Provide a Main Function 36-19
Generate Reentrant C Code . 36-22
Examine the Generated Code 36-22
Run the Code 36-23
Call Reentrant Code — Multithreaded with Persistent Data (UNIX Only)
36-24
MATLAB Code for This Example 36-24
Provide a Main Function 36-24
Generate Reentrant C Code . 36-27
Examine the Generated Code 36-28
Run the Code 36-28
xxxvi ContentsTroubleshooting Code Generation Problems
37
JIT MEX Incompatibility Warning . 37-2
Issue . 37-2
Cause . 37-2
Solution . 37-2
JIT Compilation Does Not Support OpenMP . 37-3
Issue . 37-3
Cause . 37-3
Solution . 37-3
Output Variable Must Be Assigned Before Run-Time Recursive Call . 37-4
Issue . 37-4
Cause . 37-4
Solution . 37-4
Compile-Time Recursion Limit Reached 37-7
Issue . 37-7
Cause . 37-7
Solutions 37-7
Force Run-Time Recursion . 37-7
Increase the Compile-Time Recursion Limit 37-9
Unable to Determine That Every Element of Cell Array Is Assigned 37-10
Issue 37-10
Cause 37-10
Solution 37-11
Nonconstant Index into varargin or varargout in a for-Loop 37-14
Issue 37-14
Cause 37-14
Solution 37-14
Unknown Output Type for coder.ceval . 37-16
Issue 37-16
Cause 37-16
Solution 37-16
MEX Generated on macOS Platform Stays Loaded in Memory . 37-18
Issue 37-18
Cause 37-18
Solution 37-18
Resolve Error: Code Generator Failed to Produce C++ Destructor for
MATLAB Class 37-20
Issue 37-20
Possible Solutions . 37-20
xxxviiRow-Major Array Layout
38
Row-Major and Column-Major Array Layouts 38-2
Array Storage in Computer Memory 38-2
Conversions Between Different Array Layouts 38-2
Generate Code That Uses Row-Major Array Layout . 38-4
Specify Row-Major Layout . 38-4
Array Layout and Algorithmic Efficiency . 38-5
Row-Major Layout for N-Dimensional Arrays . 38-6
Specify Array Layout in External Function Calls . 38-7
Deep Learning with MATLAB Coder
39
Prerequisites for Deep Learning with MATLAB Coder . 39-2
MathWorks Products . 39-2
Third-Party Hardware and Software 39-2
Environment Variables 39-4
Workflow for Deep Learning Code Generation with MATLAB Coder 39-7
Networks and Layers Supported for Code Generation . 39-8
Supported Pretrained Networks . 39-8
Supported Layers 39-9
Supported Classes 39-20
int8 Code Generation 39-27
Analyze Network for Code Generation . 39-29
Check dlnetwork for Code Generation Compatibility . 39-29
Analyze Classification Network for Code Generation Compatibility 39-31
Load Pretrained Networks for Code Generation . 39-37
Load a Network by Using coder.loadDeepLearningNetwork . 39-37
Specify a Network Object for Code Generation . 39-37
Specify a dlnetwork Object for Code Generation 39-38
Generate Generic C/C++ Code for Deep Learning Networks . 39-40
Requirements 39-40
Code Generation by Using codegen . 39-40
Code Generation by Using the MATLAB Coder App 39-41
Code Generation for Deep Learning Networks with MKL-DNN . 39-43
Requirements 39-43
Code Generation by Using codegen . 39-43
Code Generation by Using the MATLAB Coder App 39-44
Code Generation for Deep Learning Networks with ARM Compute Library
39-46
Requirements 39-46
xxxviii ContentsCode Generation by Using codegen . 39-46
Code Generation by Using the MATLAB Coder App 39-49
Cross-Compile Deep Learning Code That Uses ARM Compute Library
39-51
Prerequisites 39-51
Generate and Deploy Deep Learning Code 39-52
Generate int8 Code for Deep Learning Networks 39-54
ARM Cortex-A Processors . 39-54
ARM Cortex-M Processors 39-55
Update Network Parameters After Code Generation . 39-57
Create an Entry-Point Function . 39-57
Create a Network . 39-57
Code Generation by Using codegen . 39-58
Run the Generated MEX 39-58
Update Network with Different Learnable Parameters . 39-59
Run the Generated MEX with Updated Learnables 39-59
Limitations 39-60
Deep Learning Code Generation on Intel Targets for Different Batch Sizes
39-61
Deep Learning Prediction with ARM Compute Using codegen . 39-70
Code Generation for Deep Learning on ARM Targets 39-75
Generate C++ Code for Object Detection Using YOLO v2 and Intel MKLDNN 39-80
Code Generation and Deployment of MobileNet-v2 Network to Raspberry
Pi . 39-83
Code Generation for Semantic Segmentation Application on Intel CPUs
That Uses U-Net . 39-87
Code Generation for Semantic Segmentation Application on ARM Neon
Targets That Uses U-Net 39-96
Code Generation for LSTM Network on Raspberry Pi . 39-105
Code Generation for LSTM Network That Uses Intel MKL-DNN . 39-112
Code Generation for Convolutional LSTM Network That Uses Intel MKLDNN . 39-116
Cross Compile Deep Learning Code for ARM Neon Targets 39-120
Generate INT8 Code for Deep Learning Network on Raspberry Pi . 39-126
Generate INT8 Code for Deep Learning Network on Cortex-M Target
. 39-134
xxxixGenerate Generic C/C++ Code for Sequence-to-Sequence Regression That
Uses Deep Learning 39-137
Generate Digit Images Using Variational Autoencoder on Intel CPUs
. 39-146
Post-Code-Generation Update of Deep Learning Network Parameters
. 39-152
Generate Code for LSTM Network and Deploy on Cortex-M Target 39-161
Prune Filters in a Detection Network Using Taylor Scores . 39-168
Generating Code for C++
40
C++ Code Generation . 40-2
Generate C++ Code 40-2
C++ Language Features Supported in Generated Code . 40-2
Additional Differences Between Generated C Code and C++ Code . 40-3
Generate C++ Code with Class Interface . 40-4
Generate C++ Code with a Class Interface . 40-4
Globals and Persistents in a Generated C++ Class . 40-6
Put Multiple Entry-Point Functions in the Same Class . 40-7
Organize Generated C++ Code into Namespaces . 40-9
Settings That Control Namespace Structure 40-9
Example: Generate C++ Code with Namespaces . 40-10
Integrate Multiple Generated C++ Code Projects . 40-14
Generate C++ Classes for MATLAB Classes That Model Simple and
Damped Oscillators 40-18
Simulation Data Inspector
41
View Data in the Simulation Data Inspector . 41-2
View Logged Data . 41-2
Import Data from the Workspace or a File 41-3
View Complex Data 41-5
View String Data 41-6
View Frame-Based Data . 41-9
View Event-Based Data 41-9
Import Data from a CSV File into the Simulation Data Inspector 41-11
Basic File Format . 41-11
Multiple Time Vectors 41-11
xl ContentsSignal Metadata 41-12
Import Data from a CSV File . 41-13
Microsoft Excel Import, Export, and Logging Format 41-16
Basic File Format . 41-16
Multiple Time Vectors 41-16
Signal Metadata 41-17
User-Defined Data Types . 41-19
Complex, Multidimensional, and Bus Signals 41-21
Function-Call Signals 41-21
Simulation Parameters . 41-22
Multiple Runs 41-22
Configure the Simulation Data Inspector 41-24
Logged Data Size and Location . 41-24
Archive Behavior and Run Limit 41-25
Incoming Run Names and Location 41-26
Signal Metadata to Display 41-27
Signal Selection on the Inspect Pane 41-28
How Signals Are Aligned for Comparison . 41-28
Colors Used to Display Comparison Results . 41-29
Signal Grouping 41-29
Data to Stream from Parallel Simulations . 41-30
Options for Saving and Loading Session Files 41-30
Signal Display Units . 41-30
How the Simulation Data Inspector Compares Data . 41-32
Signal Alignment . 41-32
Synchronization 41-33
Interpolation 41-34
Tolerance Specification . 41-34
Limitations 41-36
Save and Share Simulation Data Inspector Data and Views . 41-37
Save and Load Simulation Data Inspector Sessions 41-37
Share Simulation Data Inspector Views 41-38
Share Simulation Data Inspector Plots . 41-38
Create Simulation Data Inspector Report . 41-39
Export Data to the Workspace or a File . 41-40
Export Video Signal to an MP4 File 41-41
Inspect and Compare Data Programmatically 41-43
Create a Run and View the Data 41-43
Compare Two Signals in the Same Run . 41-44
Compare Runs with Global Tolerance 41-45
Analyze Simulation Data Using Signal Tolerances . 41-46
Limit the Size of Logged Data . 41-49
Limit the Number of Runs Retained in the Simulation Data Inspector
Archive . 41-49
Specify a Minimum Disk Space Requirement or Maximum Size for Logged
Data . 41-49
View Data Only During Simulation 41-50
Reduce the Number of Data Points Logged from Simulation . 41-50

#ماتلاب,#متلاب,#Matlab,

كلمة سر فك الضغط : books-world.net
The Unzip Password : books-world.net
أتمنى أن تستفيدوا من محتوى الموضوع وأن ينال إعجابكم

رابط من موقع عالم الكتب لتنزيل كتاب MATLAB Coder - User's Guide
رابط مباشر لتنزيل كتاب MATLAB Coder - User's Guide
الرجوع الى أعلى الصفحة اذهب الى الأسفل
 
كتاب MATLAB Coder - User's Guide
الرجوع الى أعلى الصفحة 
صفحة 2 من اصل 1
 مواضيع مماثلة
-
» كتاب MATLAB Coder Reference
» كتاب AutoCAD Mechanical Users Guide
» كتاب Fusion 360 - Beginners & Intermediate Users’ Guide
» كتاب AutoCAD 2024 - A Power Guide for Beginners and Intermediate Users
» كتاب SOLIDWORKS 2023 A Power Guide for Beginners and Intermediate Users

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
منتدى هندسة الإنتاج والتصميم الميكانيكى :: المنتديات الهندسية :: منتدى شروحات البرامج الهندسية-
انتقل الى: