????Group project???Qt???????棬?????????matlab???????????????????????????????????????????????????°???????????????????????????????
???????????Ubuntu 12.04.4 LTS??Matlab?汾??R2013b??
????1. ??????Matlab??????????????????·????/usr/local/MATLAB
????2. ?????Qt?????
????3. ????????.pro????????????????У?
????INCLUDEPATH += /usr/local/MATLAB/R2013b/extern/include/
????LIBS += -L"/usr/local/MATLAB/R2013b/bin/glnxa64" -leng -lmat -lmex -lmx -Wl??-rpath=/usr/local/MATLAB/R2013b/bin/glnxa64
??????·??????????????matlab??·???С?
????4.??cpp?????#include <engine.h>????????????′???

 

#include <QtGui/QApplication>
#include <QDebug>
#include <cmath>
#include <iostream>
#include <engine.h>
int main(int argc?? char *argv[])
{
// Test 1????C++?е?????????Matlab???
// [1] ???Matlab????
Engine *ep = engOpen(NULL);
if (!ep)
{   // ????Matlab?????????????棻???????NULL
qDebug() << "Can't start Matlab engine!";
exit(-1);
}
engSetVisible(ep?? false);
// [2] ??C++????乹????????????????????
const int N_SIZE = 10;
double x[N_SIZE]??y[N_SIZE];
for (int i=0; i<N_SIZE; i++) //????????x??y
{
x[i] = (i+1);
y[i] = sin(x[i]); //?????????
}
// [3] ??C++???????Matlab????
mxArray *xx = mxCreateDoubleMatrix(1??N_SIZE?? mxREAL); // ????mxArray????У?N_SIZE ?е????????
mxArray *yy = mxCreateDoubleMatrix(1??N_SIZE?? mxREAL);
// [4] ?????????????????
memcpy(mxGetPr(xx)?? x?? N_SIZE*sizeof(double)); // ??????x?????mxarray????xx??
memcpy(mxGetPr(yy)?? y?? N_SIZE*sizeof(double));
// [5] ??C++?????????????Matlab??????
engPutVariable(ep?? "xx"??xx);  // ??mxArray????xxд??Matlab????????????xx
engPutVariable(ep?? "yy"??yy);
// [6] ???Matlab????
engEvalString(ep?? "plot(xx?? yy); "); // ??Matlab???淢????????
// [7] ????C++??????????
mxDestroyArray(xx);    // ????mxArray????xx??yy
mxDestroyArray(yy);
// Test 2?????Matlab???????????
// [1] ??Matlab??????????buffer
const int BUFSIZE = 1024;
char buffer[BUFSIZE] = {'