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.
Argument |
Type |
Description |
pApp |
Object |
A valid reference to the current Excel application |
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
.)
Argument |
Type |
Description |
pVarArg |
Variant |
Receives the resulting array |
[Var0], [Var1], ... |
Variant |
Optional list of Variant s to pack into the array. From 0 to 32 arguments can be passed. |
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.
Function mysum(Optional V0 As Variant
, _
Optional V1 As Variant, _
Optional V2 As Variant, _
Optional V3 As Variant, _
Optional V4 As Variant, _
Optional V5 As Variant, _
Optional V6 As Variant, _
Optional V7 As Variant, _
Optional V8 As Variant, _
Optional V9 As Variant) As Variant
Dim y As Variant
Dim varargin As Variant
Dim aClass As Object
Dim aUtil As Object
On Error Goto Handle_Error
Set aClass = CreateObject("mycomponent.myclass.1_0")
Set aUtil = CreateObject("MWComUtil.MWUtil")
Call aUtil.MWPack(varargin,V0,V1,V2,V3,V4,V5,V6,V7,V8,V9)
Call aClass.mysum(1, y, varargin)
mysum = y
Exit Function
Handle_Error:
mysum = Err.Description
End Function
Sub MWUnpack(VarArg, [nStartAt As Long], [bAutoResize As Boolean = False], [pVar0], [pVar1], ..., [pVar31])
Unpacks an array of Variant
s into individual Variant
arguments. This function provides the reverse functionality of MWPack
and is typically used to process a varargout
cell into individual Variant
s.
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 GenVectors(v1 As Variant, v2 As Variant, _ v3 As Variant, v4 As Variant) Dim aClass As Object Dim aUtil As Object Dim v As Variant On Error GoTo Handle_Error Set aClass = CreateObject("mycomponent.myclass.1_0") Set aUtil = CreateObject("MWComUtil.MWUtil") Call aClass.randvectors(4, v) Call aUtil.MWUnpack(v,0, ,v1 ,v2 ,v3 ,v4) Exit Sub Handle_Error: MsgBox (Err.Description) End Sub
Sub MWDate2VariantDate(pVar)
Converts output dates from MATLAB to Variant
dates.
Argument |
Type |
Description |
pVar |
Variant |
Variant to be converted. |
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 Double
s 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.
Sub GenDates(Dates As Variant, num As Long, inc As Long) Dim aClass As Object Dim aUtil As Object On Error GoTo Handle_Error Set aClass = CreateObject("mycomponent.myclass.1_0") Set aUtil = CreateObject("MWComUtil.MWUtil") Call aClass.getdates(1, Dates, Cdbl(num), Cdbl(inc)) Call aUtil.MWDate2VariantDate(Dates) Exit Sub Handle_Error: MsgBox (Err.Description) End Sub
![]() | Utility Library Classes | Class MWFlags | ![]() |