File Exchange Pick of the Week

January 12th, 2007

Cleaner code in MATLAB part two

This second video in the cleaner code series talks about magic numbers, and how to avoid them. It also covers naming conventions for function names and binary variables. Use of subfunctions is also shown.

2 Responses to “Cleaner code in MATLAB part two”

  1. Martin Cohen replied on :

    I long ago got in the habit of eliminating sqrt’s from distance computations whenever possible, since the sqrt usually takes longer than computing the square of the distance. In this case, I would compare the sum of squares with r^2.

  2. Doug replied on :

    Martin,

    This is an excellent observation. I am thinking of adding another video in this series that might be able to fit in code optimizations like that.

    Thank you,
    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.