I have to rewrite some matlab code into C which will then be embedded into Matlab using MEX once again. So far, I've read some tutorials and examples in how this works for simple data structures. (I've never done that before, even though I would consider myself experienced in both Matlab and C).
So here is the problem:
I have given something like that
classdef MyClass
properties
foo;
bar;
blub;
somethingElse;
end
methods
function obj = myFun(obj) % really just some random example code
obj.foo = obj.bar;
obj.blub = 42;
for i = 1:length(obj.somethingElse)
obj.somethingElse(i) = i*i;
end;
end
end
end
I want to rewrite myFun as a MEX/C-function. If I pass a class to a MEX-function, how can I access the different properties of this class?
Thanks
A MEX file is a function, created in MATLAB®, that calls a C/C++ program. A MEX file is a function, created in MATLAB, that calls a C/C++ program or a Fortran subroutine. A MEX function behaves just like a MATLAB script or function.
To call a MEX file, put the file on your MATLAB® path. Then type the name of the file, without the file extension. If you have MEX file source code, see Build C MEX Function for information about creating the executable function.
From within your MATLAB® code, you can directly call external C/C++ code, also called custom code or legacy code. To call C/C++ functions, use coder. ceval .
To debug your MEX functions, use the disp function to inspect the contents of your MEX function variables. You cannot use save to debug MEX function variables because code generation does not support it. Code generation does not support declaration of save as extrinsic.
You have the following functions in the MEX API:
mxGetProperty and mxSetProperty
Their use is equivalent to:
value = pa[index].propname;
pa[index].propname = value;
Note that these functions create deep copies of the data. There are undocumented functions to work with shared data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With