9.4 Transferring data to theMatlabdomain 301
#include <iostream>
#include <cmath>
#include "engine.h"
using namespace std;//=======================================int main()
{//--- Data:double pi=3.14159265358;const short Nt=16; // azimuthal divisions
const short Np=32; // meridional divisionsdouble x[Nt+1][Np+1], y[Nt+1][Np+1], z[Nt+1][Np+1];double theta,ct,st,phi,cp,sp;//--- Nodes:double Dt = pi/Nt;
double Dp = 2*pi/Np;for (int i=0; i<=Nt; i++)
{
theta = Dt*i;
ct = cos(theta);
st = sin(theta);
for (int j=0; j<=Np; j++)
{
phi = Dp*j;
cp = cos(phi);
sp = sin(phi);
x[i][j]= ct;
y[i][j]= st*cp;
z[i][j]= st*sp;
}
}//--- Matlab: gataki is the matlab session nameEngine * gataki = engOpen("matlab14 -nosplash -nodesktop");//--- Establish a buffer:const int BUFSIZE=256;