Using mexCallMATLAB(nlhs, plhs, nrhs, prhs, "foo")
command we can call a function(here "foo.m") which was wrote in MATLAB from C++.
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 MATLAB class member function from C++?
In MATLAB you call a class method just like any other function:
obj.method
is the same as
method(obj)
You can easily create a similar call from within your MEX-file using mexCallMATLAB
. If any of the arrays in prhs
is of type Foo
, then MATLAB will look for a function first within that class' methods.
So for OP's example:
mxArray rhs = <mxArray of type Foo>;
mcArray los;
mexCallMATLAB(1, &lhs, 1, &rhs, "foo");
The Foo object would need to be instantiated somewhere so the easiest thing for this example would be to make the foo method static.
You could then create a Matlab wrapper function which calls Foo.staticfoo(args)
and call the Matlab wrapper function using mexCallMATLAB
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.