Hi
I am trying to print values obtained from matlab function which is called in c++ program. This is the code, I am not sure how can I print values.
#include <stdlib.h>#include <stdio.h>#include <string.h>#include "engine.h"int main(){ Engine *ep; if (!(ep = engOpen(""))) { fprintf(stderr, "\nCan't start MATLAB engine\n"); return EXIT_FAILURE; } int const SIZE=1; int const SIZE2=1; double x[SIZE][SIZE2]; x[1][1] = 1.0; mxArray *A=NULL; A=mxCreateDoubleMatrix(SIZE2, SIZE, mxREAL); memcpy((void *)mxGetPr(A), (void *)x, sizeof(double)*SIZE*SIZE2); engPutVariable(ep, "Data", A); engEvalString(ep, "newData = test_matlab(Data)"); double *cresult; mxArray *mresult; mresult = engGetVariable(ep,"newData"); cresult = mxGetPr(mresult); mxDestroyArray(A); mxDestroyArray(mresult); engClose(ep); return EXIT_SUCCESS;}
Best Answer