matlab
tips and tricks and
...
page overview:
I created this
page as a vectorization helper but it grew to become my annotated
Matlab reading cache. In order to motivate the DSP people out there, I
am showing below how one can apply a window and scale factors on a preframed signal
using no loops and minimal memory.
% For framing use buffer() or your own favorite
% Frame length: 256, Number of frames: 10000
X = randn(256,10000);
% Make a window (same for each frame)
w = hamming(256);
W = diag(sparse(w));
% This is the windowed signal, without loops
XW = W * X;
% Make a vector of random gain factors (one per frame)
g = rand(10000,1);
G = diag(sparse(g))
% Now lets scale each frame by the corresponding gain factor
XG = X * G;
% Windowing and gain scaling is just left and right product with a diagonal.
XWG = W * X * G;
local links:
Note that some of the
following documents are taken off of Mathworks' own
support site; more specifically
take a look at the
technical
notes section. Also
a very good source of information is
comp.softsys.matlab
 MATLAB
Tensor Toolbox, 20051207
Just as I was about to bite the bullet and write it myself, I finally came
across a class for multidimensional tensors. The original page describing
the toolbox can be found
here and the
code here. If you are
working with multilinear forms you will definitely appreciate this.
 GUI with MATLAB, 20050615
A presentation on how to get started with GUIs.
 Good MATLAB Programming Practices for the
NonProgrammer, 20050615
Some simple suggestions.
 Writing Fast MATLAB Code, 20050423
Once again your regular collection of standard tricks.
 MATLAB Programming Style Guidelines, 20050423
Not that you will ever start writing with such style but here is a bunch of
suggestions. Well on page 9 it reads "Avoid cryptic code", well
I don't think so. Can you deny that x'.'
is so much more beautiful than
conj(x) ??? I always prefer the second cause it's so easy to
type ... ;)
 MATLAB Tips and Tricks, 20050423
We share the same name. A collection of a lot rather straightforward
code. Take a look, you might find what you are looking for or might
not ...

Why does LPC return a different prediction error than ARYULE?, 20040316
This Matlab bug has caused me hours of frustration. Petr Fousek suffered too
...
 MEXfiles Guide, 20040304
I still don't know if it is possible to operate 'inplace' on a mex array. Do I
really need to reallocate memory for output?
 Why do I receive a segmentation violation mentioning
the toolbox cache when starting MATLAB?, 20040303
Well you got to love this line: "Some customers have found that updating
the driver for your video card can resolve the problem as well." Remember
that we are talking about an XML toolbox cache file corruption ...
 Numerical Computing with MATLAB,
(pdf cached), (code
cached), 20040220
A very good read. Most of the chapters of the book along with the code are
available online.
 MATLAB
Array Manipulation Tips and Tricks (pdf cached),
(code cached), 20030614
Again a very good read.
 Floating Point, IEEE Standard unifies
arithmetic model (pdf), 20030614

Why do I receive errors when overloading SUBSREF for types {} and . for MATLAB
OOPS objects (31436) (pdf), 20030611
If you have ever tried to write your own classes in Matlab chances are you
run into the problems described in this article.

Simplify your code with commaseparated lists (pdf), 20030608
Two very valuable cases are presented. The first is the fftshift()
function which is all you need to know about the most flexible indexing method
in Matlab. When you really understand fftshift() take a look at flipdim() and
you are done. The second is the problems with subsref() / subsasgn() and the
overloaded numel() functions in userdesigned classes.
 What's the big deal ? (pdf),
20030608
The two main uses of deal are explained:
[C{:}] = deal(S.name); % The only way to
initialize cell arrays
[S.name] = deal(C{:});
 Exploiting the
commaseparated list (pdf), 20030608
There is no exploiting going on here. This is a very easy reading.

Think
Globally, Act Locally (pdf), 20030608
A nice pattern for variable number number of input arguments is mentioned.
function heatmodel(varargin)
defaultValues
= {100,72,350};
nonemptyIdx
= ~cellfun(�isempty�,varargin);
defaultValues(nonemptyIdx) = varargin(nonemptyIdx);
[sz normalTemp hotTemp] = deal(defaultValues{:});

Picking up the Pace with the MATLAB profiler (pdf), 20030608
Some pretty interesting optimization tricks like the use of 1i variable,
loop variable confinement and unrolling of complex arithmetic. Had MathWorks
done this for all those cryptic "x" messages in profiler life would be easier
...

Is it possible to run MATLAB in the background under UNIX ? (86) (pdf),
20030604
Guess what? It is!

Techniques for Debugging MATLAB Mfiles (1207) (pdf),
mfiles (zip), 20030513
If you are a newbie and you're having problems with basic errors download
the above mfiles. Chances are your error is identified and solved in one of
the examples.

What Is the EVAL Function, When Should I Use It, and How Can I Avoid It ?
(1103) (pdf) 20030319
Info about the dreaded triple quotes ''' in eval(). A really nasty way to
disable quote's special functionality. In other languages one would expect to
escape the quote by \' but not in Matlab. What you really need to know is
that:
>> eval('disp(''''''This is a string'''''')')
'This is a string'

Is it possible to call a dynamic linked library from MATLAB ? (33513) (pdf),
mfiles (exe) 20030309
Now one can simply wrap her code in a DLL and have it called from Matlab.
Pointers to any type of Matlab variables can be defined straight in the
workspace and can be passed to C/C++. Call by reference is now possible.
 Printing and
Exporting Guide (1206) (pdf) 20030227
 Exporting
Figures for Publication B (pdf), mfiles
(zip) 20030227
Use this library in your next LaTeX paper ...
 Matrix Indexing in Matlab
(pdf)
 Memory management guide
(1106) (pdf)
 Accelerating Matlab (R13) (pdf)
The new version of Matlab uses JustInTime code generation. Your for loops
have never been that fast !

Fast manipulation of multidimensional arrays in Matlab (pdf)
(Older version
here)
 How do I
vectorize my code ? (1109) (pdf)
 Matlab
array manipulation tips and tricks (pdf)
See up for the newest version of this document.
 Matlab Tricks (pdf)
 comp.softsys.matlab.faq (pdf)
 Vectorization (pdf)
[Home]