Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

A simple question about the getting results using Matlab engine.

1 vue (au cours des 30 derniers jours)
Gil
Gil le 7 Mar 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by