Data Conversion Rules
This topic describes the data conversion rules for the MATLAB® Compiler™ components. These components are dual interface Microsoft® COM objects that support data types compatible with Automation.
Note
Automation (formerly called OLE Automation) is a technology that allows software packages to expose their unique features to scripting tools and other applications. Automation uses the Component Object Model (COM), but may be implemented independently from other OLE features, such as in-place activation.
When a method is invoked on a MATLAB Compiler component, the input parameters are converted to the MATLAB internal array format and passed to the compiled MATLAB function. When the function exits, the output parameters are converted from the 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 VARIANT
s in C/C++, and Visual Basic® provides native language support for this type.
Note
This discussion of data refers to both VARIANT
and
Variant
data types. VARIANT
is the C++
name and Variant
is the corresponding data type in Visual Basic.
See the Visual Studio® documentation for definitions and API support for COM
VARIANT
s. VARIANT
variables are self
describing and store their type code as an internal field of the structure.
The following table lists the VARIANT
type codes supported by
MATLAB
Compiler components.
VARIANT Type Codes Supported
VARIANT Type
Code(C/C++) | C/C++ Type | Variant Type
Code(Visual Basic) | Visual BasicType | Definition |
---|---|---|---|---|
VT_EMPTY | — | vbEmpty | — | Uninitialized |
VT_I1 | char | — | — | Signed one-byte character |
VT_UI1 | unsigned | vbByte | Byte | Unsigned one-byte character |
VT_I2 | short | vbInteger | Integer | Signed two-byte integer |
VT_UI2 | unsigned short | — | — | Unsigned two-byte integer |
VT_I4 | long | vbLong | Long | Signed four-byte integer |
VT_UI4 | unsigned long | — | — | Unsigned four-byte integer |
VT_R4 | float | vbSingle | Single | IEEE® four-byte floating-point value |
VT_R8 | double | vbDouble | Double | IEEE eight-byte floating-point value |
VT_CY | CY + | vbCurrency | Currency | Currency value (64-bit integer, scaled by 10,000) |
VT_BSTR | BSTR + | vbString | String | String value |
VT_ERROR | SCODE + | vbError | — | An |
VT_DATE | DATE + | vbDate | Date | Eight-byte floating point value representing date and time |
VT_INT | int | — | — | Signed integer; equivalent to type
|
VT_UINT | unsigned int | — | — | Unsigned integer; equivalent to type |
VT_DECIMAL | DECIMAL + | vbDecimal | — | 96-bit (12-byte) unsigned integer, scaled by a variable power of 10 |
VT_BOOL | VARIANT_BOOL + | vbBoolean | Boolean | Two-byte Boolean value (0xFFFF = True; 0x0000 = False) |
VT_DISPATCH | IDispatch* | vbObject | Object |
|
VT_VARIANT | VARIANT + | vbVariant | Variant |
|
<anything>|VT_ARRAY | — | — | — | Bitwise combine |
<anything>|VT_BYREF | — | — | — | Bitwise combine |
+ Denotes Windows-specific type. Not part of standard C/C++. |
The following table lists the rules for converting from MATLAB to COM.
MATLAB to COM VARIANT Conversion Rules
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
| A multidimensional cell array converts to a
| |
structure |
|
| A MATLAB
|
char | A 1-by-1 | A 1-by-L | Arrays of character vectors are not supported as
|
sparse |
|
| A MATLAB sparse array is converted to an
|
double | A real 1-by-1 double matrix converts to a
| A real multidimensional double matrix converts to a
| Complex arrays are passed to and from
compiled MATLAB functions using the |
single | A real 1-by-1 single matrix converts to a
| A real multidimensional single matrix converts to a
| Complex arrays are passed to and from compiled MATLAB functions
using the |
int8 | A real 1-by-1 | A real multidimensional | Complex arrays are passed to and from compiled MATLAB functions
using the |
uint8 | A real 1-by-1 | A real multidimensional | Complex arrays are passed to and from compiled MATLAB functions
using the |
int16 | A real 1-by-1 | A real multidimensional | Complex arrays are passed to and from compiled MATLAB functions
using the |
uint16 | A real 1-by-1 | A real multidimensional | Complex arrays are passed to and from compiled MATLAB functions
using the |
int32 | A 1-by-1 | A multidimensional | Complex arrays are passed to and from compiled MATLAB functions
using the |
uint32 | A 1-by-1 | A multidimensional | Complex arrays are passed to and from compiled MATLAB functions
using the |
Function handle |
|
| Not supported |
Java® class |
|
| Not supported |
User class |
|
| Not supported |
logical |
|
|
The following table lists the rules for conversion from COM to MATLAB.
COM VARIANT to MATLAB Conversion Rules
VARIANT Type | MATLAB Data Type (scalar or array data) | Comments |
---|---|---|
VT_EMPTY | Not applicable | 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 |
VT_ERROR | int32 | |
VT_DATE | double | 1. |
VT_INT | int32 | |
VT_UINT | uint32 | |
VT_DECIMAL | double | |
VT_BOOL | logical | |
VT_DISPATCH | (varies) |
Currently,
support exists for Excel®
|
<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 |