Matlab function handle as a argument called by C?
이전 댓글 표시
The MATLAB function x = fmincon(fun,x0,A,b) has a function handle @fun, when it compiles into a DLL, the function form is mlx- or mlf- as follow:
mlxFmincon(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
mlfFmincon(int nargout, mxArray** X, mxArray** FVAL, mxArray** EXITFLAG, mxArray** OUTPUT, mxArray** LAMBDA, mxArray** GRAD, mxArray** HESSIAN, mxArray* FUN, mxArray* X_in1, mxArray* A, mxArray* B, mxArray* Aeq, mxArray* Beq, mxArray* LB, mxArray* UB, mxArray* NONLCON, mxArray* options, mxArray* varargin);
The problem is how can I call this function in the visual studio? Is it a way to use the function handle as a argument just like the function pointer in C? thanks.
답변 (1개)
Walter Roberson
2012년 7월 29일
0 개 추천
You cannot directly call MATLAB functions, as function handles do not point to machine code. You need to ask the MATLAB Engine to evaluate the expression.
댓글 수: 4
iar
2012년 7월 29일
Walter Roberson
2012년 7월 29일
Only MATLAB can invoke MATLAB function handles. Function handles in MATLAB are a data structure that include (amongst other things) a reference to a data block that stores MATLAB code in a pre-parsed threaded-interpreter format that needs to be interpreted by the MATLAB Engine. MATLAB .m code does not compile down to machine language, only to linked data structures.
lin he
2012년 7월 30일
is there a way to pass c++ functions to fmincon?
Walter Roberson
2012년 7월 30일
No.
You might, however, be able to pass the function handle of a mex function or of something you have loadlibrary()'d
카테고리
도움말 센터 및 File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!