294 Introduction to C++ Programming and Graphics
Note that we have included theengine.hheader file. A typical session is listed
below:
a=4
>>
a=
4
b=9
>>
b=
9
c=a+b
>>
c=
13
0
>>
ans =
0
where>>is theMatlabline prompt.
In retrospect, this code accomplishes little. This session could have been
established by callingMatlabdirectly rather than through the C++ code.
Problems
9.3.1. Use the codemexec.ccto compute and print (a) the square root of a
number, and (b) the product of two matrices defined inMatlab.
9.3.2. Investigate the significance of the buffer size.
9.4 Transferring data to theMatlabdomain
In practice, we want to generate data in the C++ domain and askMatlabto
lend us computational and graphics services.
Consider the arrayx[M][N]consisting of floating point numbers regis-
tered in double precision. To transfer this array intoMatlab,weworkinthree
stages:
- First, we introduce anmxArray, withMrows andN columns, where
the prefixmxstands forMatlabexecutable. This is done using the
command:
mxArray * arrayname = mxCreateDoubleMatrix (M, N, mxTYPE);