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.

  1. 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.
  2. 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).

  3. Install lightspeed. It provides optimized implementations of common operations, including a C replacement for repmat.m.
  4. Profile your code to find bottlenecks:
    profile on
    myfun;
    profile report
  5. 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 MinkaAccelerating Matlab

Accelerating Matlab的更多相关文章

  1. Matlab tips and tricks

    matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it g ...

  2. 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 ...

  3. Matlab 绘制三维立体图(以地质异常体为例)

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  4. Matlab slice方法和包络法绘制三维立体图

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  5. Matlab 高斯_拉普拉斯滤波器处理医学图像

    前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...

  6. MATLAB中绘制质点轨迹动图并保存成GIF

    工作需要在MATLAB中绘制质点轨迹并保存成GIF以便展示. 绘制质点轨迹动图可用comet和comet3命令,使用例子如下: t = 0:.01:2*pi;x = cos(2*t).*(cos(t) ...

  7. linux下配置matlab运行环境(MCR)

    在安装好的matlab下有MCR(MatlabCompilerRuntime)在matlab2011/toolbox/compiler/deploy/glnxa64下找到MCRInstaller.zi ...

  8. EMD分析 Matlab 精华总结 附开源工具箱(全)

    前言: 本贴写于2016年12与15日,UK.最近在学习EMD(Empirical Mode Decomposition)和HHT(Hilbert-Huang Transform)多分辨信号处理,FQ ...

  9. Atitit MATLAB 图像处理 经典书籍attilax总结

    Atitit MATLAB 图像处理 经典书籍attilax总结 1.1. MATLAB数字图像处理1 1.2. <MATLAB实用教程(第二版)>((美)穆尔 著)[简介_书评_在线阅读 ...

随机推荐

  1. python之集合,函数,装饰器

    本节主要内容如下: 1. set集合 2. 函数 -- 自定义函数 -- 内置函数 3. 装饰器 一. set 集合: 一个无序且不重复的序列. tuple算是list和str的杂合(杂交的都有自己的 ...

  2. 微信video标签全屏无法退出bug 本文系转载

    安卓(android)微信里面video播放视频,会被强制全屏,播放完毕后还有腾讯推荐的视频,非常讨厌..强制被全屏无法解决,但是视频播放完毕后退出播放器可以解决.方法就是视频播放完毕后,用音频aud ...

  3. 用户登录流程详解 +volley(StringRequest)

    在实习期间由于要求使用volley,所以第一次开始接触volley,从一开始的迷茫陌生,到疯狂的查找各种资料,通过在项目中用到的实际问题,我想做一些总结,所以写了这篇文章.下面我将介绍我理解的用户登录 ...

  4. self dismissModalViewControllerAnimated:YES 无效(dismissviewcontrolleranimated无效)

    作为一个viewController(VC),想要消失的时候可以从parent VC里面调用dismissModalViewControllerAnimated来消去改VC,也可以在该VC里面手动调用 ...

  5. [Android Pro] android 4.4 Android原生权限管理:AppOps

    reference : http://m.blog.csdn.net/blog/langzxz/45308199 reference : http://blog.csdn.net/hyhyl1990/ ...

  6. java动态生成excel打包下载

    @SuppressWarnings("unchecked") public String batchExport() throws DBException{ @SuppressWa ...

  7. ios 多线程小结----- GCD篇

    //3 GCD(充分利用设备的多盒)-------------屏蔽了线程,只能看见任务 队列步骤两步,定制任务,将任务添加到队列.GCD将添加的任务,放到线程中去执行,自动执行,自动释放原则:先进先出 ...

  8. NYOJ之猴子吃桃问题

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAIMCAIAAACIcqa9AAAgAElEQVR4nO3dO3Li3BaG4TMJcgbi1A

  9. Cannot return from outside a function or method

    最近发现myeclipse10中有几处bug 比如: Cannot return from outside a function or method onClick="return chec ...

  10. mysql常用表/视图管理语句

    查看所有表  show tables; 查看表/视图结构 desc 表名/视图名: 查看建表过程  show create table 表名: 查看建视图过程 show create view 视图名 ...