- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
matlab提速技巧
1.首先要学会用profiler.1.1. 打开profiler.To open the Profiler, select View - Profiler from the MATLAB desktop, or type profile viewer in the Command Window. The MATLAB Profiler opens.在我的机器上是: 在matlab desktop下,Desktop-Profiler.在M文件编辑器下,Tools-Open Profiler.1.2. 运行profiler可以把要运行的code拷入Run this code后面的输入框里。You can run this example[t,y] = ode23(lotka,[0 2],[20;20])也可以输入要运行的M文件名。1.3.Click Start Profiling (or press Enter after entering the statement).1.4. 查看Profile Detail Report会告知你哪些代码消耗了多少时间,可以找到哪些函数或那些代码行消耗了主要的时间,或者是经常被调用
也可以用stopwatch Timer函数,计算程序消耗时间Use tic and toc as shown here.tic?? - run the program section to be timed -toc
2. 加速1:向量化MATLAB is a matrix language, which means it is designed for vector and matrix operations. You can often speed up your M-file code by using vectorizing algorithms that take advantage of this design. Vectorization means converting for and while loops to equivalent vector or matrix operations.
i = 0;for t = 0:.01:1000??? i = i+1;??? y(i) = sin(t);end
运行时间为30.776秒。改为向量化代码:t = 0:.01:1000;y = sin(t);运行时间为0秒
Functions Used in VectorizingSome of the most commonly used functions for vectorizing are:?all?diff?ipermute?permute?reshape?squeeze?any?find?logical?prod?shiftdim?sub2ind?cumsum?ind2sub?ndgrid?repmat?sort?sum??3. 加速2:Preallocating Arrays(预分配空间)You can often improve code execution time by preallocating the arrays that store output results. Preallocation makes it unnecessary for MATLAB to resize an array each time you enlarge it. Use the appropriate preallocation function for the kind of array you are working with.Preallocation also helps reduce memory fragmentation if you work with large matrices.
4.加速其他方法:Coding Loops in a MEX-File for Speed
If there are instances where you must use a for loop, consider coding the loop in a MEX-file. In this way, the loop executes much more quickly since the instructions in the loop do not have to be interpreted each time they execute.
Functions Are Faster Than S
文档评论(0)