欢迎来到天天文库
浏览记录
ID:33828844
大小:370.76 KB
页数:36页
时间:2019-02-28
《C _with_Matlab.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、C++withMatlabTutorial55:148DigitalImageProcessing2007.10.16WhyuseC/C++withMatlab?•Matlabcanbeslow•C++canbefast–HowcanweintegrateC++’sspeedwithMatlab’sconvenience?•Goal:-Implementcriticalfunctionswith(fast)C++code,anduse(slow)Matlabcodefordatastructuremanagement(whichc
2、anbedifficult/annoyinginC++)HowdoweintegrateC++withMatlab?•MatlaballowstheuseofMEXfiles–MEXfilesarepre-compiledfilesthatarecalledfromMatlab–CanbecompiledfromMatlab.mfiles–CanalsobecompiledfromexternalC++code.•ThiswillbeourfocusThecomponentsofaMEXfile•EveryMEXfileconsi
3、stsoftwoparts:–AgatewayroutinethatinterfaceswithMatlab.ThisistheentrypointfortheC++code.MustbecalledmexFunction()–Anynumberofsubroutinesthatarecalledfromthegatewayroutine.Thebulkofyourcomputationwillbeinsidethesesubroutines.ThecomponentsofaMEXfile•MEXI/O:•Thegatewayro
4、utineispassedfourparameters:intnlhs,mxArray*plhs[],intnrhs,mxArrary*prhs[]•nlhs:thenumberofoutputs•plhs[]:anarrayofoutputs•nrhs:thenumberofinputs•prhs[]:anarrayofinputsTutorial:•WewillcreateaMEXfiletoimplementamedianfilter•ImplementedinC++usingM$VisualStudio2005•MEXco
5、dewillbecontainedinaDLL(Dynamic-LinkLibrary)Tutorial:•OpenVisualStudio2005•Start->ProgramFiles->ProgrammingTools->MicrosoftVisualStudio2005Tutorial:•File->New->Project•SelectVisualC++•SelectWin32•selectwin32project•nameitMedianFilter•OKTutorial:•Click‘Next’•Select“DLL
6、”•Check“ExportSymbols”•Check“EmptyProject”•Click“Finish”Tutorial:•Project->AddNewItem•Select“Code”•Highlight“C++File”•Nameit“mexFunction.cpp”•AddTutorial:•Project->MedianFilterProperties•Expand“ConfigurationProperties”•Expand“C/C++”•Highlight“General”•Clickinthe“Addit
7、ionalIncludeDirectories”field•Clickthe“…”button•Clickthe“NewLine”button•Clickthe“…”button•Browseto“C:ProgramFilesMathworksMatlabR2007aexterninclude”•OKTutorial:•Project->MedianFilterProperties(CONTINUED)•Highlight“Preprocessor”•Clickinthe“PreprocessorDefinitions
8、”field•Clickthe“…”button•Add“MATLAB_MEX_FILE”onanewline•OK•Highlight“CodeGeneration”•Change“RuntimeLibrary”to“Multi-threaded
此文档下载收益归作者所有