MATLAB: How to call MATLAB object’s method from C++

cmexoop

Hi
Using bellow command we can easily call a function(here "foo.m") which was wrote in MATLAB from C++.
mexCallMATLAB(nlhs, plhs, nrhs, prhs, "foo")
But what if "foo" is a method of a class?
classdef Foo < handle
...
function out = foo(obj, in)
end
end
Is there any straightforward or trick to call member function from C++?

Best Answer

Call it just like a normal function with your Foo object as the input argument. E.g., if you have an object of class Foo at the m-file level:
x = Foo(whatever);
Then pass it into a mex routine:
Foo_mex(x);
Inside the Foo_mex.c file you would have something like this:
int i;
if( nrhs ) {
i = mexCallMATLAB(0,NULL,1,prhs,"foo");
:
etc