1.首先对Compiler进行适当的配置,方法是在Matlab命令窗口输入:
Mbuild –setup
2.将M文件编译为独立可执行文件的语法是:
>>mcc –m myfunctionname.m
myfunctionname.exe就是最后的可执行文件的名称。
3.将/MATLAB701/toolbox/compiler/deploy/win32中的MCRinstaller.exe安装到要运行该程序的计算机上
4.将编译生成的相相关文件拷贝到同一目录下,运行myfunctionname.ext即可执行程序
5.此时程序会出现command窗口,影响美观。
有人写好了包避免它的出现,下载地址为:http://www.mathworks.com/matlabcentral/fileexchange/3909
注意它的说明文件:
This program will hide the command window of compiled programs in all versions of Microsoft Windows. To use, change the name in the "suppress.ini" file to the name of your MATLAB EXE file, then run "suppress.exe". You may rename "suppress.exe", but you may not rename "suppress.ini" without editing and recompiling the source code. The files "suppress.exe", "suppress.ini", and your EXE file must all be in the same directory. This utility was created using NSIS (http://nsis.sf.net/). The default settings will run the "test.exe" program included in the ZIP file.
需要将suppress.ini内的路径更改,然后执行suppress.exe即可。