Writing Fast Matlab Code #1: Introduction
1 Introduction
Matlab is a prototyping environment, meaning it focuses on the ease of development with language flexibility, interactive debugging, and other conveniences lacking in performance-oriented languages like C and Fortran. While Matlab may not be as fast as C, there are ways to bring it closer.
Disclaimer
This is not a beginner’s tutorial to Matlab, but a tutorial on performance. The methods discussed here are generally fast, but no claim is made on what is fastest. Use at your own risk.
Before beginning our main topic, let’s step back for a moment and ask ourselves what we really want. Do we want the fastest possible code?—if so, we should switch to a performance language like C. Probably more accurately, we want to spend less time total from developing, debugging, running, and until finally obtaining results. This section gives some tips on working smart, not hard.
M-Lint Messages
In more recent versions of Matlab, the integrated editor automatically gives feedback on possible code errors and suggested optimizations. These messages are helpful in improving a program and in learning more about Matlab.
for k = 1:NumTrials r = rand; x(k) = runsim(r); end hist(x); % Plot histogram of simulation outputs
m-lint message:‘x’ might be growing inside a loop. Consider preallocating for speed.
Hold the mouse cursor over underlined code to read a message. Or, see all M-Lint messages at once with Tools → M-Lint → Show M-Lint Report.
Organization
- Use a separate folder for each pro ject
A separate folder for each project keeps related things together and simplifies making copies and backups of project files. - Write header comments, especially H1.
The first line of the header comment is called the H1 comment. Type help(cd) to get a listing of all project files and their H1 comments. - Save frequent console commands as a script.
If you find yourself repeating certain commands on the console, save them as a script. Less typing means fewer opportunities for typos.
Avoid losing data
- Don’t use clear all in a script.
This is an unfortunate common practice—any important variables in the base workspace will be irretrievably lost. - Beware of clobber.
“File clobber” refers to the kind of data loss when a file is accidentally overwritten with another one having the same filename. This phenomenon can occur with variables as well:>> result = big operation(input1); % Store the result of a time−consuming operation ... >> result = big operation(input2); % Run again with another input
Variable result was clobbered and the first output was lost.
- Beware of what can crash MATLAB.
While Matlab is generally reliable, crashes are possible when using third-party MEX functions or extremely memory-intensive operations, for example, with video and very large arrays.
Now with good working habits covered, we begin our discussion of writing fast Matlab code. The rest of this article is organized by topic, first on techniques that are useful in general application, and next on specific computational topics (table of contents is on the first page).
1 Introduction
Matlab is a prototyping environment, meaning it focuses on the ease of development with language flexibility, interactive debugging, and other conveniences lacking in performance-oriented languages like C and Fortran. While Matlab may not be as fast as C, there are ways to bring it closer.
Disclaimer This is not a beginner’s tutorial to Matlab, but a tutorial on performance. The methods discussed here are generally fast, but no claim is made on what is fastest. Use at your own risk.
Before beginning our main topic, let’s step back for a moment and ask ourselves what we really want. Do we want the fastest possible code?—if so, we should switch to a performance language like C. Probably more accurately, we want to spend less time total from developing, debugging, running, and until finally obtaining results. This section gives some tips on working smart, not hard.
M-Lint Messages
In more recent versions of Matlab, the integrated editor automatically gives feedback on possible code errors and suggested optimizations. These messages are helpful in improving a program and in learning more about Matlab.
for k = 1:NumTrials r = rand;
x(k) = runsim(r);
end
l xl might be growing inside a loop. Consider preallocating for speed.
hist(x); % Plot histogram of simulation outputs
|
Hold the mouse cursor over underlined code to read a message. Or, see all M-Lint messages at once with Tools → M-Lint → Show M-Lint Report.
Organization
❼ Use a separate folder for each pro ject.
A separate folder for each project keeps related things together and simplifies making copies and backups of project files.
❼ Write header comments, especially H1.
The first line of the header comment is called the H1 comment. Type help(cd) to get a listing of all project files and their H1 comments.
1
❼ Save frequent console commands as a script.
If you find yourself repeating certain commands on the console, save them as a script. Less typing means fewer opportunities for typos.
Avoid losing data
❼ Don’t use clear all in a script.
This is an unfortunate common practice—any important variables in the base workspace will be irretrievably lost.
❼ Beware of clobber.
“File clobber” refers to the kind of data loss when a file is accidentally overwritten with another one having the same filename. This phenomenon can occur with variables as well:
>> result = big operation(input1); % Store the result of a time−consuming operation
…
>> result = big operation(input2); % Run again with another input
Variable result was clobbered and the first output was lost.
❼ Beware of what can crash MATLAB.
While Matlab is generally reliable, crashes are possible when using third-party MEX functions or extremely memory-intensive operations, for example, with video and very large arrays.
Now with good working habits covered, we begin our discussion of writing fast Matlab code. The rest of this article is organized by topic, first on techniques that are useful in general application, and next on specific computational topics (table of contents is on the first page).
Popularity: 1% [?]
Filterbank-Based Fingerprint Matching
With identity fraud in our society reaching unprecedented proportions and with an increasing emphasis on the emerging automatic personal identification applications, biometrics-based verification, especially fingerprint-based identification, is receiving a lot of attention. There are two major shortcomings of the traditional approaches to fingerprint representation. For a considerable fraction of population, the representations based on explicit detection of complete ridge structures in the fingerprint are difficult to extract automatically. The widely used minutiae-based representation does not utilize a significant component of the rich discriminatory information available in the fingerprints. Local ridge structures cannot be completely characterized by minutiae. Further, minutiae-based matching has difficulty in quickly matching two fingerprint images containing different number of unregistered minutiae points. The proposed filter-based algorithm uses a bank of Gabor filters to capture both local and global details in a fingerprint as a compact fixed length FingerCode. The fingerprint matching is based on the Euclidean distance between the two corresponding FingerCodes and hence is extremely fast. We are able to achieve a verification accuracy which is only marginally inferior to the best results of minutiae-based algorithms published in the open literature. Our system performs better than a state-of-the-art minutiae-based system when the performance requirement of the application system does not demand a very low false acceptance rate. Finally, we show that the matching performance can be improved by combining the decisions of the matchers based on complementary (minutiae-based and filter-based) fingerprint information.
Index Terms: Biometrics, FingerCode, fingerprints, flow pattern, Gabor filters, matching, texture, verification. The localization of core point represents the most critical step of the whole process. A good matching requires an accurate positioning, so the small errors must also be avoided. The usage of complex filtering techniques, can greatly improve accuracy. On the other side, for very poor quality input images, a traditional algorithm can fail even using a hierarchical approach with a multiscale filtering.
We have developed a novel, hybrid technique for core point detection. This algorithm, to our knowledge, is not documented in literature and is based on the mutual information that is exchanged between improved procedures. The core point location is more accurately detected by this merging of multiple techniques.
This new algorithm was tested on FVC2004 training fingerprint images. Test results are available on request. Please email us in order to obtain them.
Demo code (protected P-files) available for performance evaluation. (Matlab Image Processing Toolbox is required).
|
We recommend to check the secure connection to PayPal, in order to avoid any fraud.
This donation has to be considered an encouragement to improve the code itself. |
|||||||||||||||
|
Pro Version
Fingerprint Recognition System 5.3 – Click here for your donation. In order to obtain the source code you have to pay a little sum of money: 30 EUROS (less than 42 U.S. Dollars).
|
|||||||||||||||
|
Once you have done this, please email us luigi.rosa@tiscali.it
As soon as possible (in a few days) you will receive our new release of Fingerprint Recognition System. Alternatively, you can bestow using our banking coordinates:
|
|||||||||||||||
The authors have no relationship or partnership with The Mathworks. All the code provided is written in Matlab language (M-files and/or M-functions), with no dll or other protected parts of code (P-files or executables). The code was developed with Matlab 14 SP1. Matlab Image Processing Toolbox is required. The code provided has to be considered “as is” and it is without any kind of warranty. The authors deny any kind of warranty concerning the code as well as any kind of responsibility for problems and damages which may be caused by the use of the code itself including all parts of the source code.
Popularity: 2% [?]
OfficeDoc Professional
Product description:
OfficeDoc reads/writes/appends and formats data, images & figure screenshots in Microsoft Office documents, from within the Matlab environment. Supported document formats include XLS (Excel), DOC (Word) & PPT (PowerPoint). Opening/closing COM server connection and files is user-controllable, enabling very fast sequential writes. Numerous format properties enable highly customizable output.
This function is meant as a direct replacement for Matlab’s built-in xlsread/xlswrite functions. There is no comparable built-in Matlab support for DOC/PPT.
OfficeDoc has 2 basic syntaxes:
-
[data,status,errMsg] = officedoc(file, action, propName,propVal, ...)
- actions: ‘open’/'read’/'write’/'format’/'close’/'display’
- properties: 66 different props – too many to list here (see inline documentation). The Professional version enables all properties, whereas the demo version enables only a handful. Click here to see the full list of properties.
-
helpText = officedoc('help', helpType)
- helpTypes: ‘props’/'examples’/'xls’/'doc’/'ppt’
The first syntax is the main usage form. Due to the vast number of possible actions and properties, an extensive documentation facility was built-in: the second syntax form above.
OfficeDoc comes a long way in enabling highly customizable document output. However, there will always be certain unsupported capabilities. The built-in documentation provides examples on accessing and using such features via direct COM calls.
A basic usage example follows. Click here for more detailed examples:
[file,status] = officedoc(fileName, 'open', 'mode','append'); status = officedoc(file, 'write', 'title','My data', 'data',[1,2;3,4], 'image',gcf, 'bold',1,'fgcolor','b'); status = officedoc(file, 'close');
Bugs and suggestions:
OfficeDoc was tested on Office 11 (XP) & Matlab 6.0 (R12) – 7.4 (R2007a), but might also work on earlier versions of Matlab & Office. OfficeDoc was only tested on Windows PC, and is expected to fail on other systems. Please report any incompatibilities or other bugs/suggestions to YMASoftware@gmail.com.
Online resources:
- officedoc.zip – the downloadable program (both Demo & Pro)
- Detailed help text
- Table of supported properties
- Detailed usage examples
Installation:
Download and unzip the officedoc.zip file, and place the file’s contents anywhere on your Matlab path. The same file is used for both Demo and Pro versions. To unlock the Pro features, purchase a license here and follow the instructions below.
After initial installation, you can always download the latest OfficeDoc version here – you will not need to reinstall your license access code.
License:
In order to receive the license (access code) that will unlock the professional features of OfficeDoc, please send an email with the following details to YMASoftware@gmail.com:
- your Matlab license number (output of the license command)
- your full name as entered during purchase
- your OfficeDoc order confirmation number and date
After receiving your information, your OfficeDoc Pro license (access code) will be sent to you within 2 business days. Purchasing an OfficeDoc Pro license entitles you (the Licensee) to a single access code, on a single computer running the Matlab license that you specified in your email. You are also entitled to email notifications of any upgraded version or fixes, free of charge (unless, of course, you choose to unsubscribe).
Non-professional Matlab licenses (e.g., student or demo) are not entitled to OfficeDoc Pro.
Warranty Disclaimer:
This Program is delivered “as-is” and YMA Software makes and the Licensee receives no additional express or implied warranties. YMA Software and its Licensors hereby expressly disclaim any and all other conditions, warranties, or other terms of any kind or nature concerning the Programs, Documentation, and Software Maintenance Services (including, without limitation, any with regard to infringement, merchantability, quality, accuracy, or fitness for a particular purpose or Licensee’s purpose). YMA Software also expressly disclaims any warranties that may be implied from usage of trade, course of dealing, or course of performance. The Programs, Documentation, and Software Maintenance Services are provided with all faults, and the entire risk of satisfactory quality, performance, accuracy, and effort is with Licensee. YMA Software does not warrant that the Programs and Documentation will operate without interruption or be error free. Licensee accepts responsibility for its use of the Programs and the results obtained therefrom.
or
Buy Pro
Popularity: 2% [?]
Matlab 7.9 Latest Features
The Mathworks has presented the new Matlab R2009b I report what’s new on this version.
This version, released with 2009b on 04 Sep 2009, includes the following enhancements:
Development Environment
- New File Exchange desktop tool (4:51), providing direct access to user-contributed files on MATLAB Central
- Enhanced Plot Selector in the Workspace browser (3:26), providing access to additional plot types and customization of plot favorites
- Enhanced Current Folder browser (2:18), providing improved navigation, display, and searching for files
- Customizable keyboard shortcuts (4:15), including consistent defaults for the MATLAB Editor and Command Window
- Enhanced Help browser (1:21), providing more detailed search results with grouping by product and result type
- Expanded MATLAB file publishing (0:38), providing support for PDF as an output file format
Language and Programming
- Ability to specify unused input and output arguments (2:49) to a function with the tilde (~) character
File I/O and External Interfacing
- mmreader function expanded to support Motion JPEG 2000 files
- New Tiff object to write tiled images and a broad set of metadata within TIFF files
- Expanded low-level HDF5 file access to support H5L, H5O, and H5DS interfaces
- Support for MATLAB scalar indexing into Microsoft .NET Framework arrays
Performance and Large Data Set Handling
- Ability to perform FFTs on vectors larger than 2 GB
- Multithreaded computation support for sort, filter, bsxfun, sparse matrix QR decomposition, gamma functions, and error functions
- Sparse matrix performance improvements for basic math, binary and relational operators, and exponential functions
Popularity: 7% [?]
Fast Surface Reconstruction: Delaunay2.5D
Filed under: Algorithms, Computational Geometry, Graphics
Can a surface reconstructor be faster than a 2D mesher?
It is coming soon the Delaunay2.5D algorithm a new fast surface reconstructor. It is currently in a prototype state, still have to code pre-processor and post-processor parts. I will include it in my thesis.
This algorithm can deal with millions of points in a matter of a few second, it is basically faster than a 2d delaunay triangulation. For this reason I am also thinking about extend it to 2D and 3D triangulations.
More infos about the algorithm performances and how does it work will be given in future. At the time I only have this video demostration and a demo version.I was impatient to publish something about it
.
Delaunay2_5D has been released here.
Popularity: 28% [?]




















































