Accelerating Matlab
Matlab is a very useful programming environment, but it also has many inefficiencies. You might think that these are unavoidable, but in fact it is possible to fix most of them, without significantly changing your programs. This page describes some easy ways to modify the Matlab environment to make programs run faster.
- Install Marcel Leutenegger's package of elementary functions. They speed up functions like exp and log by a factor of 3 or more, with no loss of accuracy. They directly replace the functions in Matlab, so no program modification is required.
- Run mex -setup and select a good compiler. The default compiler (lcc) does not produce very good code.
To use Microsoft Visual Studio .NET 2003 version 7.1, you will first need to install a patch. Unfortunately, while Visual Studio 7.1 generally produces good code, it has a performance bug in the intrinsic exp function. To get around this, edit the mex options file (C:\MATLAB6p5p1\bin\win32\mexopts\msvc71opts.bat) to read:
set OPTIMFLAGS=/MD -O2 -Oy- /Oi- -DNDEBUG
After changing the compiler, you should re-compile your mex files, and re-install any packages including mex (such as lightspeed).
- Install lightspeed. It provides optimized implementations of common operations, including a C replacement for repmat.m.
- Profile your code to find bottlenecks:
profile on
myfun;
profile report - Avoid loops by writing 'vectorized' code. See the MathWorks' Vectorization Guide, Marios Athineos's tips and tricks, and the routines in lightspeed (such assqdist).
Efficient ways to do common tasks
Manipulate sets of integers
The fastest way to do this is with sparse logical vectors. If you want to use sorted arrays of integers instead, beware that the Matlab functions setdiff, union, etc. are not optimized for this case and will be a bottleneck. Optimized functions for the sorted case are included in lightspeed.
Represent a graph
Use a sparse logical adjacency matrix, and use matrix operations whenever possible. For example, if G is symmetric (i.e. an undirected graph) then G*G gives the number of neighbors in common to nodes i and j, for all (i,j). See Kevin Murphy's graph toolbox.
Sample random numbers from various distributions
Use the functions provided in lightspeed.
Read XML
Peter Rysadter's XML parser was the fastest, but is no longer available. Check out the links at Undocumented XML functionality.
文章转载自 Tom Minka 的 Accelerating Matlab。
Accelerating Matlab的更多相关文章
- Matlab tips and tricks
matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it g ...
- Deep Learning 27:Batch normalization理解——读论文“Batch normalization: Accelerating deep network training by reducing internal covariate shift ”——ICML 2015
这篇经典论文,甚至可以说是2015年最牛的一篇论文,早就有很多人解读,不需要自己着摸,但是看了论文原文Batch normalization: Accelerating deep network tr ...
- Matlab 绘制三维立体图(以地质异常体为例)
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab slice方法和包络法绘制三维立体图
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab 高斯_拉普拉斯滤波器处理医学图像
前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...
- MATLAB中绘制质点轨迹动图并保存成GIF
工作需要在MATLAB中绘制质点轨迹并保存成GIF以便展示. 绘制质点轨迹动图可用comet和comet3命令,使用例子如下: t = 0:.01:2*pi;x = cos(2*t).*(cos(t) ...
- linux下配置matlab运行环境(MCR)
在安装好的matlab下有MCR(MatlabCompilerRuntime)在matlab2011/toolbox/compiler/deploy/glnxa64下找到MCRInstaller.zi ...
- EMD分析 Matlab 精华总结 附开源工具箱(全)
前言: 本贴写于2016年12与15日,UK.最近在学习EMD(Empirical Mode Decomposition)和HHT(Hilbert-Huang Transform)多分辨信号处理,FQ ...
- Atitit MATLAB 图像处理 经典书籍attilax总结
Atitit MATLAB 图像处理 经典书籍attilax总结 1.1. MATLAB数字图像处理1 1.2. <MATLAB实用教程(第二版)>((美)穆尔 著)[简介_书评_在线阅读 ...
随机推荐
- oracle 存储过程中调用存储过程
create procedure sp_name() begin ……… end 比如: create procedure pro_showdbs() show datebase; end //用ex ...
- centos 7 python2.7.5升级到3.5.2
centos 7 python2.7.5升级到3.5.2 下载python3.5.2 wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2 ...
- Python: 安装BeautifulSoup4
python3.4.3 安装BeautifulSoup4: 使用pip install 安装: 在命令行cmd之后输入,pip install BeautifulSoup4 BeautifulSoup ...
- 获取指定文件下的所有file文件
/** * 描述:获取所有的文件列表 * @param file * @param list * @return */ private List<File> getAllFiles(Fil ...
- 【轮子】发现一个效果丰富酷炫的Android动画库
没有什么比发现一个好轮子更让人开心的了. 这个库分分钟提高交互体验 :AndroidViewAnimations 一张图说明一切 配置和使用也相当简单 GitHub地址
- 【leetcode】Merge Two Sorted Lists(easy)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- 【leetcode】Minimum Depth of Binary Tree (easy)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场
题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过l ...
- Please see the 'svn upgrade' command
svn: E155036: Please see the 'svn upgrade' command svn: E155036: Working copy '/home/easwy/dev' is t ...
- [Android Pro] Gradle tip #3-Task顺序
reference to : http://blog.csdn.net/lzyzsd/article/details/46935405 原文链接 我注意到我在使用Gradle的时候遇到的大多数问题都是 ...