私は、各反復でフレームを処理し、行列を生成するコードを持っています。私の最終的な目標は、各フレームの行列の進化を調べるために行列データをmatlabに送ることです。 これを達成するために、私はヘッダファイル(helper.h)に静的変数Engineを定義しました。メイン()プログラムでMatlab "engine.h"をC++から正しく使用する
#include "engine.h";
#include "mex.h";
static Engine *engine;
私は一度だけエンジンを開く:私はMatlabのエンジンに送信する行列を取得する場所
#include helper.h
main(){
if (!(engine = engOpen(NULL))) {
MessageBox ((HWND)NULL, (LPSTR)"Can't start MATLAB engine",(LPSTR) "pcTest.cpp", MB_OK);
exit(-1);}
//here comes frame processing using a while loop
.
. //a function is called (defined in matrix.cpp)
.
//frame processing ends
}
そしてmatrix.cpp内部があるので、私は何かを
#include helper.h
mxArray *mat;
mat = mxCreateDoubleMatrix(13, 13, mxREAL);
memcpy(mxGetPr(mat),matrix.data, 13*13*sizeof(double));
engPutVariable(engine, "mat", mat);
私は最も効率的な方法でエンジンにポインタを使いたいと思います。私はちょうどmatlabエンジンを正しく使う方法についてちょっと納得しています。
matlabのマニュアルとサンプルは、同じファイル内のすべてのコードを持ち、繰り返しを使用していないため、助けにならなかったので、歓迎されるでしょう。前もって感謝します。エンジンポインタについて解く
EDIT
まず問題。解決策はそれをexternとして宣言しています。
#include "engine.h";
#include "mex.h";
extern Engine *engine;
とmain.cppにして
#include helper.h
Engine *engine=NULL;
main(){}
。 –
[OK]を私はここで質問を始めた:http://stackoverflow.com/questions/8847504/sending-a-matrix-with-each-iteration-matlab-engine-hc –