| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
result = h.Feval('functionname', numout, arg1, arg2, ...)
result = Feval(h, 'functionname', numout, arg1, arg2, ...)
result = invoke(h, 'Feval', 'functionname', numout, ...
arg1, arg2, ...)HRESULT Feval([in] BSTR functionname, [in] long nargout, [out] VARIANT* result, [in, optional] VARIANT arg1, arg2, ...)
Feval(String functionname, long numout, arg1, arg2, ...) As Object
Feval executes the MATLAB function specified by the string functionname in the Automation server attached to handle h.
Indicate the number of outputs to be 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 | Description |
|---|---|
Pass the value itself | To pass any numeric or string value, specify the value in the Feval argument list: a = h.Feval('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 = h.Feval('sin', 1, x); |
Reference a server variable | To reference a variable defined in the server, specify the variable name followed by an equals (=) sign: h.PutWorkspaceData('x', 'base', -pi:0.01:pi);
a = h.Feval('sin', 1, 'x=');MATLAB does not reassign the server variable. |
To display the output from Feval in the client window, assign a return value.
Server function names, like Feval, are case sensitive when using the first two syntaxes shown in the Syntax section.
COM functions are available on Microsoft Windows systems only.
This section contains a number of examples showing how to use Feval to execute MATLABcommands on a MATLAB Automation server.
Concatenate two strings in the server by passing the input strings in a call to strcat through Feval (strcat deletes trailing spaces; use leading spaces):
h = actxserver('matlab.application');
a = h.Feval('strcat', 1, 'hello', ' world')
MATLAB displays:
a =
'hello world'Perform the same concatenation, passing a string and a local variable clistr that contains the second string:
clistr = ' world';
a = h.Feval('strcat', 1, 'hello', clistr)
MATLAB displays:
a =
'hello world'In this example, the variable srvstr is defined in the server, not the client. Putting an equals sign after a variable name (for example, srvstr=) indicates it is a server variable, and the variable is not defined in the client:
% Define the variable srvstr on the server.
h.PutCharArray('srvstr', 'base', ' world')
% Pass the name of the server variable using 'name=' syntax
a = h.Feval('strcat', 1, 'hello', 'srvstr=')
MATLAB displays:
a =
'hello world'Here are the same examples shown above, but written for a Visual Basic® .NET client. These examples return the same strings as shown above.
Pass the 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"
Matlab.Feval("strcat", 1, out, "hello", clistr)Pass the name of a variable defined on the server:
Matlab.PutCharArray("srvstr", "base", " world")
Matlab.Feval("strcat", 1, out, "hello", "srvstr=")Feval Return Values — MATLAB Client. 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.
The numout argument in the following example specifies that Feval return three outputs from the fileparts function. As is the case here, you can request fewer than the maximum number of return values for a function (fileparts can return up to four):
a = h.Feval('fileparts', 3, 'd:\work\ConsoleApp.cpp')
MATLAB displays:
a =
'd:\work'
'ConsoleApp'
'.cpp'Convert the returned values from the cell array a to char arrays:
a{:}
MATLAB displays:
ans = d:\work ans = ConsoleApp ans = .cpp
Here is the same example, but coded in Visual Basic. Define the argument returned by Feval as an Object.
Dim Matlab As Object
Dim out As Object
Matlab = CreateObject("matlab.application")
Matlab.Feval("fileparts", 3, out, "d:\work\ConsoleApp.cpp")Execute, PutFullMatrix, GetFullMatrix, PutCharArray, GetCharArray
![]() | feval | fft | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |