MATLAB Excel Builder | ![]() ![]() |
Data Conversion Rules
This section describes the data conversion rules for MATLAB Excel Builder components. Excel Builder components are dual interface COM objects that support COM Automation compatible data types. When a method is invoked on a Excel Builder component, the input parameters are converted to MATLAB internal array format and passed to the compiled MATLAB function. When the function exits, the output parameters are converted from MATLAB internal array format to COM Automation types.
The COM client passes all input and output arguments in the compiled MATLAB functions as type VARIANT. The COM VARIANT
type is a union of several simple data types. A type VARIANT variable can store a variable of any of the simple types, as well as arrays of any of these values. The Win32 Application Program Interface (API) provides many functions for creating and manipulating VARIANTs in C/C++, and Visual Basic provides native language support for this type. See the Visual Studio documentation for definitions and API support for COM VARIANTs. VARIANT variables are self describing and store their type code as an internal field of the structure.
Table B-1 lists the VARIANT
type codes supported by Excel Builder components. Table B-2 and Table B-3 list the data conversion rules between COM VARIANTs and MATLAB arrays.
MATLAB Data Type |
VARIANT type for Scalar Data |
VARIANT type for Array Data |
Comments |
cell |
A 1-by-1 cell array converts to a single VARIANT with a type conforming to the conversion rule for the MATLAB data type of the cell contents. |
A multidimensional cell array converts to a VARIANT of type VT_VARIANT|VT_ARRAY with the type of each array member conforming to the conversion rule for the MATLAB data type of the corresponding cell. |
|
structure |
VT_DISPATCH |
VT_DISPATCH |
A MATLAB struct array is converted to an MWStruct object. (SeeClass MWStruct.) This object is passed as a VT_DISPATCH type. |
char |
A 1-by-1 char matrix converts to a VARIANT of type VT_BSTR with string length = 1. |
A 1-by-L char matrix is assumed to represent a string of length Lin MATLAB. This case converts to a VARIANT of type VT_BSTR with a string length = L. char matrices of more than one row, or of a higher dimensionality convert to a VARIANT of type VT_BSTR|VT_ARRAY . Each string in the converted array is of length 1 and corresponds to each character in the original matrix. |
Arrays of strings are not supported as char matrices. To pass an array of strings, use a cell array of 1-by-L char matrices. |
sparse |
VT_DISPAATCH |
VT_DISPATCH |
A MATLAB sparse array is converted to an MWSparse object. (See Class MWSparse.) This object is passed as a VT_DISPATCH type. |
double |
A real 1-by-1 double matrix converts to a VARIANT of type VT_R8 . A complex 1-by-1 double matrix converts to a VARIANT of type VT_DISPATCH . |
A real multidimensional double matrix converts to a VARIANT of type VT_R8|VT_ARRAY . A complex multidimensional double matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
single |
A real 1-by-1 single matrix converts to a VARIANT of type VT_R4 . A complex 1-by-1 single matrix converts to a VARIANT of type VT_DISPATCH . |
A real multidimensional single matrix converts to a VARIANT of type VT_R4|VT_ARRAY . A complex multidimensional single matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
int8 |
A real 1-by-1 int8 matrix converts to a VARIANT of type VT_I1 . A complex 1-by-1 int8 matrix converts to a VARIANT of type VT_DISPATCH . |
A real multidimensional int8 matrix converts to a VARIANT of type VT_I1|VT_ARRAY . A complex multidimensional int8 matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
uint8 |
A real 1-by-1 uint8 matrix converts to a VARIANT of type VT_UI1 . A complex 1-by-1 uint8 matrix converts to a VARIANT of type VT_DISPATCH . |
A real multidimensional uint8 matrix converts to a VARIANT of type VT_UI1|VT_ARRAY .A complex multidimensional uint8 matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
int16 |
A real 1-by-1 int16 matrix converts to a VARIANT of type VT_I2 . A complex 1-by-1 int16 matrix converts to a VARIANT of type VT_DISPATCH . |
A real multidimensional int16 matrix converts to a VARIANT of type VT_I2|VT_ARRAY . A complex multidimensional int16 matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
uint16 |
A real 1-by-1 uint16 matrix converts to a VARIANT of type VT_UI2 . A complex 1-by-1 uint16 matrix converts to a VARIANT of type VT_DISPATCH . |
A real multidimensional uint16 matrix converts to a VARIANT of type VT_UI2|VT_ARRAY . A complex multidimensional uint16 matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
int32 |
A 1-by-1 int32 matrix converts to a VARIANT of type VT_I4 . A complex 1-by-1 int32 matrix converts to a VARIANT of type VT_DISPATCH . |
A multidimensional int32 matrix converts to a VARIANT of type VT_I4|VT_ARRAY . A complex multidimensional int32 matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
uint32 |
A 1-by-1 uint32 matrix converts to a VARIANT of type VT_UI4 . A complex 1-by-1 uint32 matrix converts to a VARIANT of type VT_DISPATCH . |
A multidimensional uint32 matrix converts to a VARIANT of type VT_UI4|VT_ARRAY . A complex multidimensional uint32 matrix converts to a VARIANT of type VT_DISPATCH . |
Complex arrays are passed to and from compiled M-functions using the MWComplex class. See Class MWComplex.) |
VT_EMPTY |
VT_EMPTY |
Not supported |
|
VT_EMPTY |
VT_EMPTY |
Not supported |
|
User class |
VT_EMPTY |
VT_EMPTY |
Not supported |
logical |
VT_Bool |
VT_Bool|VT_ARRAY |
VARIANT Type |
MATLAB Data Type (scalar or array data) |
Comments |
VT_EMPTY |
N/A |
Empty array created. |
VT_I1 |
int8 |
|
VT_UI1 |
uint8 |
|
VT_I2 |
int16 |
|
VT_UI2 |
uint16 |
|
VT_I4 |
int32 |
|
VT_UI4 |
uint32 |
|
VT_R4 |
single |
|
VT_R8 |
double |
|
VT_CY |
double |
|
VT_BSTR |
char |
A VARIANT of type VT_BSTR converts to a 1-by-L MATLAB char array, where L = the length of the string to be converted. A VARIANT of type VT_BSTR|VT_ARRAY converts to a MATLAB cell array of 1-by-L char arrays. |
VT_ERROR |
int32 |
|
VT_DATE |
double |
1. VARIANT dates are stored as doubles starting at midnight Dec. 31, 1899. MATLAB dates are stored as doubles starting at 0/0/00 00:00:00. Therefore, a VARIANT date of 0.0 maps to a MATLAB numeric date of 693960.0. VARIANT dates are converted to MATLAB double types and incremented by 693960.0.2. VARIANT dates can be optionally converted to strings. See Data Conversion Flags for more information on type coercion. |
VT_INT |
int32 |
|
VT_UINT |
unit32 |
|
VT_DECIMAL |
double |
|
VT_BOOL |
logical |
|
VT_DISPATCH |
(varies) |
IDispatch* pointers are treated within the context of what they point to. Objects must be supported types with known data extraction and conversion rules or expose a generic "Value" property that points to a single VARIANT type. Data extracted from an object is converted based upon the rules for the particular VARIANT obtained. Currently, support exists for Excel Range objects as well as Excel Builder types MWStruct , MWComplex , MWSparse , and MWArg . See Utility Library Classes for information on Excel Builder types. |
<anything>|VT_BYREF |
(varies) |
Pointers to any of the basic types are processed according to the rules for what they point to. The resulting MATLAB array contains a deep copy of the values. |
<anything>|VT_ARRAY |
(varies) |
Multidimensional VARIANT arrays convert to multidimensional MATLAB arrays, each element converted according to the rules for the basic types. Multidimensional VARIANT arrays of type VT_VARIANT|VT_ARRAY convert to multidimensional cell arrays, each cell converted according to the rules for that specific type. |
![]() | MATLAB Compiler Output | Array Formatting Flags | ![]() |