PDA

View Full Version : invoking Matlb through QT



sal
20th May 2010, 12:48
Hi,

I am trying to invoke matlab using the QProcess class, however, it is not working.
Each time matlab is invoked, it flashes for a second and dissapears. There are no such
issues while invoking other processes such as emacs, Firefox etc.
Please help.
Thanks.

int main(int argc, char *argv[]) {

QApplication app(argc, argv);
QStringList argo, list;
QProcess exec;
argo<<"-nojvm -nosplash -r 'addmatrix(2,7)'";
exec.start("matlab", argo);
return app.exec();
}

JD2000
20th May 2010, 14:18
I seem to recall that anything following the run (-r) option had to be in double quotes. This may be your problem.

Have you tried starting matlab without any arguments?

exec.start("matlab")

schnitzel
22nd May 2010, 22:43
Here is how I got this to work:
link the following matlab libs:

LIBS += -L "c:/Program Files/MATLAB/R2007b/bin/win32" \
-leng -lmat -lmex -lmwblas -lmwlapack -lmwmathutil -lmx -ldfblas -ldflapack

Then in your program, invoke the engine like so:


#include <engine.h>
....
Engine *ep = engOpen(NULL);
QString tmp = QString("numcycles = 0;");
engEvalString(ep,tmp.toStdString().c_str());


you can also work with arrays and variables - consult the matlab documentation and search for engGetVariable and engPutVariable

good luck