User`s guide
Modifying Flags
3-15
x(1,2) = 12
x(2,1) = 21
x(2,2) = 22
var2 = x
Set aClass = New mycomponent.myclass
Call aClass.foo(1,y1,var1)
Call aClass.foo(1,y2,var2)
Exit Sub
Handle_Error:
MsgBox(Err.Description)
End Sub
Here, two Variant variables, var1 and var2 are constructed with the same
numerical data, but internally they are structured differently.
var1 is a 2-by-2
array of
Variants with each element containing a 1-by-1 Double, while var2 is
a 1-by-1
Variant containing a 2-by-2 array of Doubles. According to the default
data conversion rules listed in Table B-3, COM VARIANT to MATLAB
Conversion Rules, on page B-10,
var1 converts to a 2-by-2 cell array with each
cell occupied by a 1-by-1
double, and var2 converts directly to a 2-by-2 double
matrix. The
InputArrayFormat flag controls how arrays of these two types are
handled. As it turns out, the two arrays in the previous example both convert
to double matrices because the default value for the
InputArrayFormat flag is
mwArrayFormatMatrix. This default is used because, as it turns out, array data
originating from Excel ranges is always in the form of an array of
Variants
(like
var1 of the previous example), and MATLAB functions most often deal
with matrix arguments. But what if you really want a cell array? In this case,
you set the
InputArrayFormat flag to mwArrayFormatCell. Do this by adding
the following line after creating the class and before the method call.
aClass .MWFlags.ArrayFormatFlags.InputArrayFormat =
mwArrayFormatCell
Setting this flag presents all array input to the compiled MATLAB function as
cell arrays.
Similarly, you can manipulate the format of output arguments using the
OutputArrayFormat flag. You can also modify array output with the
AutoResizeOutput and TransposeOutput flags.
AutoResizeOutput is used for Excel Range objects passed directly as output
parameters. When this flag is set, the target range automatically resizes to fit