Matlab生成P文件及exe文件方法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.Matlab生成P文件方法:
P文件是对应M文件的一种预解析版本(prepar sed versio n)。
因为当你第一次执行M文件时,Matlab需要将其解析(parse)一次(第一次执行后的已解析内容会放入内存作第二次执行时使用,即第二次执行时无需再解析),这无形中增加了执行时间。
所以我们就预先作解释,那么以后再使用该M文件时,便会直接执行对应的已解析版本,即P文件。
但又因为Ma tlab的解析速度非常快,一般不用自己作预解析。
只有当一些程序要调用到非常多的M文件时,如GUI应用程序时,才会作预解析,以增加以后的调用速度。
P文件可以用来作保密代码之用,如果你给别人一个M文件,别人可以打开来看到你所有的代码和算法。
如果你的代码不想被别人看到,那可以给他P文件。
pcode函数也可以应用在M函数文件。
Matlab命令:pcode
pcodefun
pcode*.m
pcodefun1 fun2 ...
pcode... -inplac e
Descri ption
pcodefun obfusc ates(i.e., shroud s) M-file fun.m for the purpos e of protec tingits propri etary source code. The encryp ted M-code is writte n to P-file fun.pin the curren t direct ory. The origin al M-file can be anywhe re on the search path.If the inputfile reside s within a packag e and/or classdirect ory, then the same packag e and classdirect ories are applie d to the output file. See exampl e 2, below.pcode*.m create s P-filesfor all the M-filesin the curren t direct ory.pcodefun1 fun2 ... create s P-filesfor the listed
functi ons.pcode... -inplac e create s P-filesin the same direct ory as the M-files.An erroroccurs if the filescannot be create d.
2.Matlab编译生成e x e可执行文件
1、首先要保证你的程序是函数型的,而不是脚本形式的。
如果是脚本形式的也不要紧,只需要在脚本文件第一行添加functi on []=name()即可。
2、新建一个De ploym ent projec t.(File->new->Deploy mentprojec t)
3、在Build设计你的主函数入口。
Packag e设置打包的文件。
根据情况是否ADD MCR.(可使安装包中带有MCR文件,即安装matlab运行环境(这个可以保证安装的使用都不用安装m atla b)).
4、点击Buil d编译完成即可。
上述编译完成后是一个压缩包,点击后自动解压安装,注意如果有其它一些图标文件时,需在上述过程中把文件加入进来一起打包。