参数传递的简单问题
#include <vcl.h>
#pragma hdrstop
#include "matrix.h"
#include "Engine.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Engine *ep;
if (!(ep == engOpen(NULL))) {
MessageBox ((HWND)NULL, (LPSTR)"Can't start MATLAB engine",
(LPSTR) "Engwindemo.c", MB_OK);
exit(-1);
}
engEvalString(ep, "ezplot('sin(x)+2*x');");
engClose(ep);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
int a; char buffer[200];
//int *T;
int array[8]={1,3,4,5,7,2,23,15};
mxArray *S = NULL, *R= NULL, *O=NULL;// mxArray *r;
Engine *eng;
eng=engOpen(NULL);
S=mxCreateDoubleMatrix(1,8,mxREAL);
mxSetName(S, "S");
memcpy((char*) mxGetPr(S),(char *) array, 8*sizeof(int));
engPutArray(eng, S); //将变量X置入Matlab的工作空间
engEvalString(eng, "[result order]=sort(S)"); //计算
engOutputBuffer(eng, buffer, 200);
R=engGetArray(eng, "result");
O=engGetArray(eng, "order");
engClose(eng); //关闭Matlab引擎,结束调用
mxDestroyArray(S); //释放变量
mxDestroyArray(R);
mxDestroyArray(O);
现在R,O应该是计算出来了,但是我不知道怎么把结果传出来,哪位大侠帮帮忙,谢谢了
分不够了一定会加!!!