9.4 Transferring data to theMatlabdomain 303
− 1
−0.5
0
0.5
(^1) − 1
0
− 1 1
−0.5
0
0.5
1
y
xzFigure 9.4.3 Drawing of a sphere generated byMatlabthrough C++ code.//--- Finish the session:cout << "Hit return to continue\n";fgetc(stdin);return 0;
}Figure 9.4.3 shows the generated graphics display.
Note that the C++ data matrixz[Nt+1][Np+1]is passed toMatlabas
an (Np+1)×(Nt+ 1) matrix using the statement:
mxArray * zz = mxCreateDoubleMatrix(Np+1, Nt+1, mxREAL);Animation of a bouncing circle
The following code contained in the fileanimation.ccanimates the motion
of a bouncing circle inside a square box. When the center of the circle hits one
of the boundaries, the motion is reflected by switching the sign of the horizontal
or vertical velocity.