Download MATLAB Compiler User`s Guide
Transcript
Type Imputation Type Imputation The MATLAB interpreter views all variables in M-files as a single object type — the MATLAB array. All MATLAB variables, including scalars, vectors, matrices, strings, cell arrays, and structures are stored as MATLAB arrays. The mxArray declaration corresponds to the internal data structure that MATLAB uses to represent arrays. The MATLAB array is the C language definition of a MATLAB variable. To generate efficient C code from an M-file, the MATLAB Compiler analyzes how the variables in the M-files are assigned values and how these values are used. The goal of this analysis is to determine which variables can be downsized to a smaller data type (a C int or a C double). This analysis process is called type imputation; the MATLAB Compiler imputes a data type for a variable. For example, if the MATLAB Compiler sees [m,n] = size(a); then the MATLAB Compiler probably imputes the C int type for variables m and n because in MATLAB the result of this operation always yields integer scalars. In some cases, the MATLAB Compiler has to read several lines of code in order to impute properly. For example, if the MATLAB Compiler sees [m,n] = size(a); m = m + .25; then the MATLAB Compiler imputes the C double data type for variable m. Note: Specifying assertions and pragmas, as described later in this chapter, can greatly assist the type imputation process. Type Imputation Across M-Files If an M-file calls another M-file function, the MATLAB Compiler reads the entire contents of the called M-file function as part of the type imputation 4-3