Info

此问题已关闭。 请重新打开它进行编辑或回答。

A simple question about the getting results using Matlab engine.

1 次查看(过去 30 天)
Hi,
I am trying the following simple code to compute the sum of two numbers:
double *x;
mxArray *m_X;
m_X=mxCreateDoubleMatrix(1,1,mxREAL);
x=new double();
*x=3;
memcpy((void *)mxGetPr(m_X),(void *)x,sizeof(double)*1);
engPutVariable(ep,"x",m_X);
double *s;
mxArray *m_S;
m_S=mxCreateDoubleMatrix(1,1,mxREAL);
s=new double();
*s=3;
memcpy((void *)mxGetPr(m_S),(void *)s,sizeof(double)*1);
engPutVariable(ep,"s",m_S);
engEvalString(ep,"s=sum2(x,x)");
double *cresult;
mxArray *mresult;
mresult=engGetVariable(ep,"s");
cresult=new double();
cresult=mxGetPr(mresult);
Notice I create another variable "s" and inject it into Matlab to store the results. Next, I try to call the function sum2 and store the results in "s" and then I try to get the value of "s" from Matlab. I expect the value of "s" to be 6, but it stays 3, the value it was initialized with.
What am I doing wrong? How can I get the result of calling the function "sum2" from Matlab?
Thank you,
Gil.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by