How can I pass a user defined class to a MEX-File?

5 views (last 30 days)
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

Accepted Answer

James Tursa
James Tursa on 17 Jun 2013
Edited: James Tursa on 17 Jun 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.
  1 Comment
Sina
Sina on 17 Jun 2013
Hi james; Unfortunately it's a new classdef style object. I 'll try your custom mex functions and update this post with the results Thanks Sina

Sign in to comment.

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!