How to pass arguments when calling lsqnonlin from C++ with mexCallMATLAB?

조회 수: 7 (최근 30일)
Anna Shtengel
Anna Shtengel 2016년 1월 7일
댓글: James Tursa 2016년 1월 13일
I want to run lsqnonlin which is a matlab optimization function from C++. From matlab it is called as follows:
lsqnonlin(@(x)funcHandle(x,var1,var2,..),x_initial,[],[],options);
From metlab c++ API I understood that mexCallMATLAB is the function I should use to call matlab and get the output
int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs,mxArray *prhs[],
const char *functionName);
how do I pass all the arguments to mexCallMATLAB - {funcHandle,var1,var2,..,x_initial,[],[],options}, especially the function handle? I found this "mclCreateSimpleFunctionHandle" function, but I'm not sure how to use it? I have a mexFunction implementation of the funcHandle, and created a mexw64 version of it, I think I should use that somehow..
Thanks
  댓글 수: 1
James Tursa
James Tursa 2016년 1월 13일
Are you passing the result of @(x)funcHandle(x,var1,var2,...) into the mex function? I.e., are you creating the anonymous function handle at the m-file level and then passing that into the mex routine and wondering how to call mexCallMATLAB with this?
Or are you creating var1, var2, etc inside the mex function, and then wondering how to create the function handle inside the mex routine to use to pass to lsqnonlin via mexCallMATLAB?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by