Using the C++ Math Library | ![]() ![]() |
Summary of Library Calling Conventions
Several rules express the formal mapping between the MATLAB and C++ calling conventions:
For example, the MATLAB statement A = eig(C);
translates to the
identical C++ statement A = eig(C);
.
&
. They precede the input arguments in the argument list.
For example, the MATLAB function call [ U, S, V ] = svd(X)
has three
output arguments, U
, S,
and V
, and one input argument X
. The
corresponding call in C++ is U = svd(&S, &V, X)
. Note that the two output
arguments in the argument list must be prefixed with an &
, as the C++
library requires output arguments to be passed by reference.
Tip
You can also slide the left-hand MATLAB variables to the right side (prefixing them with & ) until only one variable remains on the left-hand side. |
mwVarargout
object that can represent any number of arguments. The constructor takes 32 arguments, the first of which can be another mwVarargout
object, allowing you to create any length output argument list.
mwVarargin
object that can itself represent 32 arguments, the first of which can be another mwVarargin
object, allowing you to create any length argument list.
The following table summarizes the mapping between interpreted MATLAB functions and the same functions in the MATLAB C++ Math Library.
Exceptions to the Calling Conventions
The load()
and save()
functions do not follow the standard calling conventions for the library. For information about load()
and save()
, see Importing and Exporting MAT-File Data in Chapter 8.
![]() | Passing Any Number of Outputs | Example Program: Calling Library Functions (ex2.cpp) | ![]() |