Coder - passing extra variables to function (Function Pointer/Functor)

조회 수: 9 (최근 30일)
amin ya
amin ya 2019년 4월 25일
편집: amin ya 2019년 4월 25일
In MATLAB, whenever I want to pass extra variables to originalFunction (to keep the callerFunction code clear and abstract), I would use a function handle to pass those extra variables, and then pass the function handle into callerFunction. For example:
...ExtraVars are calculated....
fun=@(x) originalFun(x,ExtraVar1,ExtraVar2);
callerFunction(fun,OtherVariables);
Consider ExtraVars are calculated.
inside callerFunction:
function callerFunction(fun,OtherVariables)
...
output=fun(x)
...
end
However, for generating MEX code for callerFunction, I can not pass function handles as inputs to a function. How can I do this for code generation?
One way which will gross the callerFunction is to add all to ExtraVars into input arguments when fun() is called. But, this will ruin the abstraction of the function.
This is how it can be done in C/C++ using Function Pointer or Functor, however, MATLAB coder doesn't seem to support these.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by