How can I pass a user defined class to a MEX-File?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I was wondering if it is possible to pass a user defined class to the mex-file as an input? The help documentation is not clear for me, how can I have access to the data stored inside the user defined object which has a user defined class? Thanks Sina
0 Commenti
Risposta accettata
James Tursa
il 17 Giu 2013
Modificato: James Tursa
il 17 Giu 2013
Pass it in just like any other variable.
If it is an old-style class (using @classname directory with multiple files) you can mostly treat it like a struct inside the mex file, since it is stored exactly like a struct internally (just with a different class designator). That is, you can use mxGetField and mxGetFieldByNumber to get at the class variable data. In fact, if you use the mxIsStruct function on the variable it will return true.
If it is a new classdef style object, your options for manipulating it inside a mex routine are very limited. TMW only supplies two functions for manipulating classdef object data, mxGetProperty and mxSetProperty. Unfortunately both of these functions use deep data copies to get the job done. If you want to work with the data without deep data copies you will have to use my custom mex functions, mxGetPropertyPtr and mxSetPropertySharedDataCopy. You can get mxGetPropertyPtr here:
I have not yet published mxSetPropertySharedDataCopy, but I do have the function finally working. I will try to get it published in the next week or so. Let me know if you need it.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!