PDA

View Full Version : ARRAYLAB phylosophy: MATLAB code with minimum number of loops



Paolo De Leva
03-01-2006, 09:34 PM
Dear subscribers,

this is a short note about my recent three postings:

1) The MULTIPROD toolbox for MATLAB (2nd posting with corrected format)
2) MATLAB toolbox: Vector Algebra for Multidimensional Arrays
2) REFSYS function for MATLAB: Defining Cartesian Reference Systems
based on Point Positions

All my functions accept as input arrays of vectors or matrices ("block
arrays"). They allow you to process multiple vectors or matrices in a single
step and with no loops. They perform automatically, with no loops:

- multiple transformations (MULTIPROD)
- multiple transpositions (MULTITRANSP)
- multiple orientation matrix definitions (REFSYS)
- multiple vectorial operations (VECTOR ALGEBRA TOOLBOX)

The philosophy is this: the "matrix laboratory" MATLAB must evolve becoming
ARRAYLAB, an "array laboratory".

MATLAB automatically evaluates A*B, when A and B are matrices, and that's a
wonderful idea. But we hardly ever work with single matrices or vectors.
Thus, we need a similar automatic tool (MULTIPROD) when A and B are arrays
of matrices or vectors OF ANY SIZE (whatever you prefer)... By the way,
MULTIPROD is even quicker than the equivalent loops, because it uses
advanced index vectorization techniques.

I encourage other subscribers to follow the same philosophy. It makes our
code much more readable and, what's more important, easier to edit and
debug. Let's try and minimize the number of loop control statements in our
code. Let's avoid loops and nested loops, when possible, and substitute them
with single calls to versatile optimized functions, working with arrays of
any size and using index vectorization techniques. In other words, please
write other functions according to the same philosophy and share them with
the world.

With kind regards,

Paolo de Leva
Department of Human Movement and Sport Sciences
University Institute of Movement Science
Rome, ITALY