MATLAB COM Builder    

Class MWUtil

The MWUtil class contains a set of static utility methods used in array processing. This class is implemented internally as a singleton. It is most efficient to declare one variable of this type in global scope within each module that uses it. The methods of MWUtil are

The function prototypes use Visual Basic syntax.

Sub MWInitApplication(pApp As Object)

Used with MATLAB Excel Builder only.

Parameters.   
Argument
Type
Description
pApp
Object
A valid reference to the current Excel application

Return Value.   None.

Sub MWPack(pVarArg, [Var0], [Var1], ... ,[Var31])

Packs a variable length list of Variant arguments into a single Variant array. This function is typically used for creating a varargin cell from a list of separate inputs. Each input in the list is added to the array only if it is nonempty and nonmissing. (In Visual Basic, a missing parameter is denoted by a Variant type of vbError with a value of &H80020004.)

Parameters.   
Argument
Type
Description
pVarArg
Variant
Receives the resulting array
[Var0], [Var1], ...
Variant
Optional list of Variants to pack into the array. From 0 to 32 arguments can be passed.

Return Value.   None.

    Remarks.   This function always frees the contents of pVarArg before processing the list.

    Example.   This example uses MWPack in a formula function to produce a varargin cell to pass as an input parameter to a method compiled from a MATLAB function with the signature

The function returns the sum of the elements in varargin. Assume that this function is a method of a class named myclass that is included in a component named mycomponent with a version of 1.0. The Visual Basic function allows up to 10 inputs, and returns the result y. If an error occurs, the function returns the error string.

Sub MWUnpack(VarArg, [nStartAt As Long], [bAutoResize As Boolean = False], [pVar0], [pVar1], ..., [pVar31])

Unpacks an array of Variants into individual Variant arguments. This function provides the reverse functionality of MWPack and is typically used to process a varargout cell into individual Variants.

Parameters.   
Argument
Type
Description
VarArg
Variant
Input array of Variants to be processed
nStartAt
Long
Optional starting index (zero-based) in the array to begin processing. Default = 0.
bAutoResize
Boolean
Optional auto-resize flag. If this flag is True, any Excel range output arguments are resized to fit the dimensions of the Variant to be copied. The resizing process is applied relative to the upper left corner of the supplied range. Default = False.

[pVar0],[pVar1], ...

Variant
Optional list of Variants to receive the array items contained in VarArg. From 0 to 32 arguments can be passed.

Return Value.   None.

Remarks.   This function can process a Variant array in one single call or through multiple calls using the nStartAt parameter.

Example.   This example uses MWUnpack to process a varargout cell into four output arguments. The varargout parameter is supplied from a method that has been compiled from the MATLAB function.

This function produces a sequence of nargout random column vectors, with the length of the ith vector equal to i. Assume that this function is included in a class named myclass that is included in a component named mycomponent with a version of 1.0. If an error occurs, a message box displays the error text.

Sub MWDate2VariantDate(pVar)

Converts output dates from MATLAB to Variant dates.

Parameters.   
Argument
Type
Description
pVar
Variant
Variant to be converted.

Return Value.   None.

Remarks.   MATLAB handles dates as double precision floating point numbers with 0.0 representing 0/0/00 00:00:00 (See Data Conversion Rules for more information on conversion between MATLAB and COM date values). By default, numeric dates that are output parameters from compiled MATLAB functions are passed as Doubles that need to be decremented by the COM date bias as well as coerced to COM dates. The MWDate2VariantDate method performs this transformation and additionally converts dates in string form to COM date types.

Example.   This example uses MWDate2VariantDate to process numeric dates returned from a method compiled from the following MATLAB function.

This function produces an n-length column vector of numeric values representing dates starting from the current date and time with each element incremented by inc days. Assume that this function is included in a class named myclass that is included in a component named mycomponent with a version of 1.0. If an error occurs, a message box displays the error text.


  Utility Library Classes Class MWFlags