Matlab Engine Does not print

4 views (last 30 days)
Debjit Pal
Debjit Pal on 27 Mar 2013
Hi All,
I have written the following code in Visual C++ 2012 to use Matlab engine by modifying the engwindemo.c code.
#######################################################################
#include Windows.h #include stdio.h #include stdlib.h #include "engine.h"
int main (int argc, char *argv[]){ printf("Debjit Pal.\n");
Engine *MyMatlabEngine;
if (!(MyMatlabEngine = engOpen(NULL))) { MessageBox ((HWND)NULL, (LPSTR)"Can't start MATLAB engine", (LPSTR) "Engwindemo.c", MB_OK); exit(-1); }
mxArray *xVal = NULL, *yVal = NULL, *d = NULL; double time[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; xVal = mxCreateDoubleMatrix(1, 10, mxREAL); memcpy((char *) mxGetPr(xVal), (char *) time, 10*sizeof(double));
engPutVariable(MyMatlabEngine, "xVal", xVal); engEvalString(MyMatlabEngine, "PI = 3.14; D = .5.*(-9.8).*xVal.^2; P = PI*.5.*(-1.2).*xVal.^3;"); //engEvalString(MyMatlabEngine, "D = .5.*(-9.8).*xVal.^2;"); //engEvalString(MyMatlabEngine, "P = PI*.5.*(-1.2).*xVal.^3;"); engEvalString(MyMatlabEngine, "Handle = figure;"); engEvalString(MyMatlabEngine, "plot(xVal,D);"); engEvalString(MyMatlabEngine, "hold on;"); engEvalString(MyMatlabEngine, "plot(xVal,P);"); engEvalString(MyMatlabEngine, "grid on;"); engEvalString(MyMatlabEngine, "title('Position vs. Time for a falling object');"); engEvalString(MyMatlabEngine, "xlabel('Time (seconds)');"); engEvalString(MyMatlabEngine, "ylabel('Position (meters)');"); engEvalString(MyMatlabEngine, "print(Handle, '-dpdf', 'MyFig.pdf');");
mxDestroyArray(xVal); engClose(MyMatlabEngine);
return 0; }
##################################################################
But what I see that no MyFig.pdf file is being generated. Can anyone suggest what I am missing here? Does all the commands of Matlab works with Matkab Engine interface?
Thanks and Regards,
Debjit.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!