Main Content

feval

Class: matlab.mex.MexHost
Namespace: matlab.mex

Evaluate C++ MEX function in MEX host process

Syntax

[result1,...,resultN] = feval(mexHost,mexFunctionName,input1,...,inputM)

Description

[result1,...,resultN] = feval(mexHost,mexFunctionName,input1,...,inputM) evaluates the named C++ MEX function in the MEX host process and returns the results. You can run multiple C++ MEX functions in a single host process.

Input Arguments

expand all

MEX host process, specified as a matlab.mex.MexHost object. Create the MEX host process using the mexhost function.

Name of the C++ MEX function to execute, specified as a character vector or a string scalar.

Example: "myMexFunction"

Data Types: char | string

Inputs to C++ MEX function. The number and type of values that can be specified as inputs depend on the C++ MEX function.

Output Arguments

expand all

Results of evaluated C++ MEX function. The number and type of values returned depend on the C++ MEX function.

Examples

expand all

Create a MEX host process and run a C++ MEX function in that process.

The arrayProduct.cpp C++ MEX file contains the source code for a function that multiplies an array by a scalar input and returns the resulting array. Open this file and save it on your MATLAB® path. Build the C++ MEX source file using the mex command. Follow the instructions in Build C++ MEX Programs to set up the MEX build.

mex arrayProduct.cpp

Create a host process. The mexhost function returns a matlab.mex.MexHost object.

mh = mexhost;

Use the feval method of the matlab.mex.MexHost object to evaluate the C++ MEX function in the host process.

result = feval(mh,"arrayProduct",10,[2,4,6,8])
result =

    20    40    60    80

Version History

Introduced in R2019a