This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Feval (COM)

Evaluate MATLAB function in Automation server


IDL Method Signature

HRESULT Feval([in] BSTR functionname, [in] long nargout, 
[out] VARIANT* result, [in, optional] VARIANT arg1, arg2, ...)

Microsoft Visual Basic Client

Feval(String functionname, long numout, 
arg1, arg2, ...) As Object


result = Feval(h,'functionname',numout,arg1,arg2,...)


result = Feval(h,'functionname',numout,arg1,arg2,...) executes the MATLAB® function specified by functionname in the Automation server attached to handle h. The function name is case-sensitive.

COM functions are available on Microsoft® Windows® systems only.

Indicate the number of outputs returned by the function in a 1-by-1 double array, numout. The server returns output from the function in the cell array, result.

You can specify as many as 32 input arguments to be passed to the function. These arguments follow numout in the Feval argument list. The following table shows ways to pass an argument.

Passing Mechanism


Pass the value itself

To pass any numeric or character value, specify the value in the Feval argument list:

a = Feval(h,'sin',1,-pi:0.01:pi);

Pass a client variable

To pass an argument assigned to a variable in the client, specify the variable name alone:

x = -pi:0.01:pi;
a = Feval(h,'sin',1,x);

Reference a server variable

To reference a variable defined in the server, specify the variable name followed by an equals (=) sign:

a = Feval(h,'sin',1,'x=');

MATLAB does not reassign the server variable.

Visual Basic .NET Examples

Passing Arguments

This example shows how to pass arguments using Feval to execute MATLAB commands on a MATLAB Automation server from a Visual Basic® .NET client.

  • Pass two strings to the MATLAB function strcat on the server:

    Dim Matlab As Object 
    Dim out As Object 
    out = Nothing 
    Matlab = CreateObject("matlab.application") 
    Matlab.Feval("strcat",1,out,"hello"," world") 
  • Define clistr locally and pass this variable:

    Dim clistr As String
    clistr = " world"
  • Pass the name of a variable defined on the server:

    Matlab.PutCharArray("srvstr","base"," world")

Defining Feval Return Values

Feval returns data from the evaluated function in a cell array. The cell array has one row for every return value. You control the number of return values using the numout argument.

Dim Matlab As Object
Dim out As Object
Matlab = CreateObject("matlab.application")

Creating Server Variables

To modify server variable A, define variables rows and cols in the client.

  • Create a matrix, A, in the server.

    Dim Matlab As Object
    Dim server_version As String
    Matlab = CreateObject("matlab.application")
  • Reshape A.

    rows = 6
    cols = 3

    MATLAB interprets A in the expression 'A=' as a server variable name.

  • The reshape function does not modify variable A.


    A is unchanged.

  • To get the result of the reshape function, use the numout argument to assign the value to C.



To display the output from Feval in the client window, assign a return value.

Introduced before R2006a

Was this topic helpful?