필터 지우기
필터 지우기

Matlab Engine Does not print

조회 수: 2 (최근 30일)
Debjit Pal
Debjit Pal 2013년 3월 27일
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.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by