Programming and Graphics

(Kiana) #1

302 Introduction to C++ Programming and Graphics


char buffer[BUFSIZE];
engOutputBuffer(gataki, buffer, BUFSIZE);

/* Matlab commands: reserve the vector ‘‘xx’’
copy into memory
import the data */

mxArray * xx = mxCreateDoubleMatrix(Np+1, Nt+1, mxREAL);
memcpy((void *)mxGetPr(xx), (void *)x, sizeof(x));
engPutVariable(gataki, "xplot", xx);

/* Matlab commands: reserve the vector ‘‘yy’’
copy into memory
import the data */

mxArray * yy = mxCreateDoubleMatrix(Np+1, Nt+1, mxREAL);

memcpy((void *)mxGetPr(yy), (void *)y, sizeof(y));
engPutVariable(gataki, "yplot", yy);

/* Matlab commands: reserve the matrix‘‘zz’’
copy into memory
import the data */

mxArray * zz = mxCreateDoubleMatrix(Np+1, Nt+1, mxREAL);

memcpy((void *)mxGetPr(zz), (void *)z, sizeof(z));
engPutVariable(gataki, "zplot", zz);

//--- Matlab session:

engEvalString(gataki, "Nt=16;");
engEvalString(gataki, "Np=32;");
engEvalString(gataki, "xplot=xplot’;yplot=yplot’;zplot=zplot’;");
engEvalString(gataki, "hold on");
engEvalString(gataki, "for i=1:Nt; for j=1:Np;
xp(1)=xplot(i,j);yp(1)=yplot(i,j);zp(1)=zplot(i,j);
xp(2)=xplot(i+1,j);yp(2)=yplot(i+1,j);zp(2)=zplot(i+1,j);
xp(3)=xplot(i+1,j+1);yp(3)=yplot(i+1,j+1);zp(3)=zplot(i+1,j+1);
xp(4)=xplot(i,j+1);yp(4)=yplot(i,j+1); zp(4)=zplot(i,j+1);
xp(5)=xplot(i,j); yp(5)=yplot(i,j); zp(5)=zplot(i,j);
patch(xp,yp,zp,zp); end; end");
engEvalString(gataki, "axis equal;");
engEvalString(gataki, "xlabel(’x’,’fontsize’,15)");
engEvalString(gataki, "ylabel(’y’,’fontsize’,15)");
engEvalString(gataki, "zlabel(’z’,’fontsize’,15)");
engEvalString(gataki, "set(gca,’fontsize’,15)");
Free download pdf