mathwork官網解決方案,說的很詳細啦。c++
https://cn.mathworks.com/matlabcentral/answers/94471-how-do-i-create-a-c-c-shared-library-with-matlab-compiler-that-can-be-used-in-a-microsoft-visual-cgit
直接上個人代碼吧:github
matlab的m文件,兩個輸入變量,沒有輸出spa
function cameraCalibrator(basis,numImages) ... ... ... end
而後在命令行中運行命令行
mcc -W cpplib:camCalibMatlab -T link:lib cameraCalibrator.m
將生成的dll,lib和h文件copy到c++代碼路徑下。code
c++中的調用爲:blog
bool CamCalibrator::run() { if (!camCalibMatlabInitialize()) { return false; } cout<<endl; cout<<"Start matlab code!"<<endl; cout<<endl; mwArray _basis(1,1,mxDOUBLE_CLASS); mwArray _numImage(1,1,mxDOUBLE_CLASS); _basis.SetData(&basis,1); _numImage.SetData(&numImage,1); cameraCalibrator(_basis,_numImage); // terminate MCR mclTerminateApplication(); cout<<"Matlab create XML file!"<<endl; return true; }
1)camCalibMatlabInitialize是必須的;2)mwArray 藉口類型;3)mclTerminateApplication 關閉調用。代碼下載: https://github.com/zhanxiage1994/Cplusplus-matlabCalibrationCamera.git