mexCallMATLAB in conjunction with OOP

1 vue (au cours des 30 derniers jours)
Yan Shou
Yan Shou le 30 Juil 2014
Commenté : Yan Shou le 11 Août 2014
Dear all,
I am working on some C codes that requires me to call matlab class objects using mexCallMATLAB, the codes runs and I can use the methods to return values, the problem I am currently experiencing is slow run time. To make the class methods to work with the C codes, I had to use mexCallMATLAB to construct the objects (due to the purpose of the program, I had to construct individual objects the same length as an input, so that each object deal with a scalar).
After the group of class objects are constructed, it it passed into another C function to be used to call the object methods using mexCallMATLAB again, with additional scalar inputs. I am able to destroy the inputs and outputs of mexCallMATLAB that are not class objects containing methods.
So my question is, is there anyway to improve my slow runtime? Am I doing the class construction the way it's supposed to? And how can I use mxDestroyArray (or other function?) to free the memory from the class objects?
Thanks for your attention and time,
best regards,
Yan
P.S. Here are parts of my codes:
/*-----------part to construct methods----------------*/
mxArray *initobjout[2], *estimclassout[1], *estimout[m];
for ( i=0; i < m; i++) {
initobjout[0] = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
initobjout[1] = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
*mxGetPr(initobjout[0]) = y[i] ;
*mxGetPr(initobjout[1]) = someparameter[0] ;
mexCallMATLAB(1, estimclassout, 2, initobjout, "SomeEstimOut");
// note: SomeEstimOut is a class object m-file
estimout[i] = estimclassout[0] ;
// mxDestroyArray(estimclassout[0]);
mxDestroyArray(initobjout[0]);
mxDestroyArray(initobjout[1]);
}
/*-----------After above part, estimout is passed into another C function to be used in the following part ----------------*/
mxArray *params[3], *xout[2];
double ph, pv;
// only included some variables' types
params[0] = *estimout;
params[1] = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
params[2] = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
ph = *w;
pv = *v;
*mxGetPr(params[1]) = ph;
*mxGetPr(params[2]) = pv;
mexCallMATLAB(2, xout, 3, params, "estim");
*zh = *mxGetPr(xout[0]) ;
*zv = *mxGetPr(xout[1]) ;
mxDestroyArray(xout[0]);
mxDestroyArray(xout[1]);
// mxDestroyArray(params[0]);
mxDestroyArray(params[1]);
mxDestroyArray(params[2]);
/*--------------------------------------------------*/
  1 commentaire
Yan Shou
Yan Shou le 11 Août 2014
Does anyone have any ideas?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Construct and Work with Object Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by