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:

    1. 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:
    1. profile on
    2. myfun;
    3. 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. Java 中常用缓存Cache机制的实现《二》

    所谓缓存,就是将程序或系统经常要调用的对象存在内存中,一遍其使用时可以快速调用,不必再去创建新的重复的实例.这样做可以减少系统开销,提高系统效率. AD: Cache 所谓缓存,就是将程序或系统经常要 ...

  2. sharepoint2013隐藏左侧导航栏更换新的

    $("#zz16_V4QuickLaunchMenu").hide()//隐藏 更换新的 <script type="text/javascript" s ...

  3. 迁移mysql数据到oracle上

    转自:http://www.cnblogs.com/Warmsunshine/p/4651283.html 我是生成的文件里面的master.sql里面的sql,一个一个拷出来的. 迁移mysql数据 ...

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

  5. Google Code Jam 2015 R1C B

    题意:给出一个键盘,按键都是大写字母.给出一个目标单词和一个长度L.最大值或者最大长度都是100.现在随机按键盘,每个按键的概率相同. 敲击出一个长度为L的序列.求该序列中目标单词最多可能出现几次,期 ...

  6. STL vector按多字段值排序

    #include <iostream> #include <vector> #include <string> #include <algorithm> ...

  7. pgpool介绍和安装经验

    Pgpool的介绍 一.介绍 是一个工作在PostgreSQL多服务器和PostgreSQL数据库客户端之间的中间件. 二.概念图 三.功能 连接池:pgpool -Ⅱ保存 连 接到PostgreSQ ...

  8. 创建一个没有边框的并添加自定义文字的UISegmentedControl

    //个性推荐 歌单 主播电台 排行榜 NSArray* promoteArray=@[@"个性推荐",@"歌单",@"主播电台",@&quo ...

  9. 创建Oracle10g ASM数据库

    概述      在真正的海量数据库环境中,DBA可能会花费很多的时间来作磁盘管理,比如一个表空间将占满整个磁盘,DBA就需要再添加一块磁盘到操作系统中,然后再在新的磁盘上创建新的数据文件,如果是单个磁 ...

  10. oracle学习不错的网站

    http://oracle-base.com/articles/linux/rlwrap.php