You can use native C++ types when calling MATLAB functions. Std::vector result = matlabPtr->feval(u"gcd", numReturned, args)
Pass vector containing MATLAB data array array In this example, MATLABEngine::feval returns a std::vector containing the three results of the gcd function call. Therefore, you must specify the actual number of returned values as the second argument to MATLABEngine::feval. In thisīy default, MATLABEngine::feval assumes that the number of returned values is one. The gcd function can return either one or threeĪrguments, depending on how many outputs the function call requests. Std::unique_ptr matlabPtr = startMATLAB() įactory.createArray( Call Function with Multiple Returned ArgumentsĬommon divisor and Bézout coefficients from the two numeric values passes as Pass the arguments to MATLABEngine::feval in a std::vector. Use the matlab::data::ArrayFactory to create two scalar int16_t arguments. The MATLABEngine::feval member function returns the results of the gcd function call. Gcd function to find the greatest common divisor of two numbers. Call Function with Single Returned Argument
For more information, see Evaluate MATLAB Statements from C++.įor information on how to setup and build C++ engine programs, see Build C++ Engine Programs. These functions enable you to create and use variables in the MATLAB workspace, but do not return values.
To evaluate MATLAB statements using variables in the MATLAB base workspace, use the matlab::engine::MATLABEngine eval and evalAsync member functions. For more information, see Redirect MATLAB Command Window Output to C++ Use stream buffers to redirect standard output and standard error from the MATLAB command window to C++. For more information, see Call Function with Multiple Returned Arguments and Control Number of Outputs.ĭefine the appropriate returned type for the results of the MATLAB function. Specify the number of outputs expected from the MATLAB function. For more information, see MATLAB Data API for C++. You can use either native C++ data types or the MATLAB Data API. Pass the function name as a matlab::engine::String.ĭefine the input arguments required by the MATLAB function.