Azzera filtri
Azzera filtri

Is it allowed for a function to have return type of mxArray?

1 visualizzazione (ultimi 30 giorni)
This is a very "noob" question probably, but is it allowed to have a function with return type mxArray? Or can I only return a pointer to mxArray?
e.g.
mxArray callEarthRotationCorrection(double traveltime, double *pX) {
mxArray output;
// Do some stuff to output
return output;
}
Currently, I'm getting a compile error at my function definition:
error: return type is an incomplete type
But it's possible that the error is related to something else I'm doing wrong in the function...

Risposta accettata

James Tursa
James Tursa il 20 Giu 2013
Modificato: James Tursa il 20 Giu 2013
mxArray is defined as an incomplete type in the API header files, hence the prohibition against declaring an mxArray type ... only a pointer is allowed. That being said, you can define your own type that resembles an mxArray header struct and then use some type punning to get at the innards of an mxArray. For an example of that you can see this submission:
But using your own mxArray definition ignores the MATLAB Memory Manager. If you create your own mxArray type and then define some variables using it, they will not be accounted for properly by the Memory Manager or in the garbage collection lists. Any attempt to use these variables in a MATLAB function, or returning them to a workspace, would risk crashing MATLAB.
Is there some particular reason why you think you need an mxArray variable (not just a pointer)? Unless you are doing something exotic, one would rarely need a variable of type mxArray ... you typically only need to work with pointers to them.

Più risposte (1)

Jan
Jan il 20 Giu 2013
You cannot simply define an mxArray by mxArray output, because the mxArray needs to be created with defining a type and a dimension, e.g. by mxCreateNumericalArray etc. Therefore output must be a pointer:
mxArray *callEarthRotationCorrection(double traveltime, double *pX) {
mxArray *output;
// Do some stuff to output
return output;
}

Categorie

Scopri di più su MATLAB Compiler in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by