MATLAB COM Builder    

Calling the Methods of a Class Instance

After you have created a class instance, you can call the class methods to access the compiled MATLAB functions. MATLAB COM Builder applies a standard mapping from the original MATLAB function syntax to the method's argument list. See section Calling Conventions for a detailed description of the mapping from MATLAB functions to COM class method calls.

When a method has output arguments, the first argument is always nargout, which is of type Long. This input parameter passes the normal MATLAB nargout parameter to the compiled function and specifies how many outputs are requested. Methods that do not have output arguments do not pass a nargout argument. Following nargout are the output parameters listed in the same order as they appear on the left side of the original MATLAB function. Next come the input parameters listed in the same order as they appear on the right side of the original MATLAB function. All input and output arguments are typed as Variant, the default Visual Basic data type.

The Variant type can hold any of the basic VB types, arrays of any type, and object references. Data Conversion describes in detail the conversion of Variants of any basic type to and from MATLAB data types. In general, you can supply any Visual Basic type as an argument to a class method, with the exception of Visual Basic UDTs. When you pass a simple Variant type as an output parameter, the called method allocates the received data and frees the original contents of the Variant. In this case it is sufficient to dimension each output argument as a single Variant. When an object type (like an Excel Range) is passed as an output parameter, the object reference is passed in both directions, and the object's Value property receives the data.

The following examples illustrate the process of passing input and output parameters from VB to MATLAB COM Builder component class methods.

The first example is a function that takes two inputs and returns one output. This function dispatches the call to a class method that corresponds to a MATLAB function of the form function y = foo(x1,x2).

The second example rewrites the same function as a subroutine:


  Visual Basic New Operator Processing varargin and varargout Arguments