Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Doug’s 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


Doug Hull is an Application Engineer at The MathWorks. A MATLAB user since 1994, he gets paid to live, eat, and breathe MATLAB! This blog is dedicated to promoting the File Exchange by highlighting files and original video content.



  • Moran: Hi Chris, I tried everything I could think of, and have sent several observations about this bug to support,...
  • odessit: Hello, I have compiled standalone application with deploytool. It would work fine, but the error is in...
  • Duane Hanselman: FYI… % strmatch replacements % strmatch is obsolete, strncmp and strcmp are built in % case...
  • Doug: Duane, I just looked, I did not see an m-lint warning against STRMATCH in 2008a. However, I seem to recall what...
  • hashem: Hi Doug, I built a GUI and write a help for it in “chm” (compiled HTML file) format, and I...
  • Tim Davis: I left out the comments in the code, above. Most of the functions should be familiar to most MATLAB users....
  • Tim Davis: I was a little confused by all the back-and-forth discussion of zero blocks. Is a block of zeros to be...
  • Tim Davis: Try this one. It doesn’t require any toolboxes, just “sparse” and “dmperm” ....
  • Duane Hanselman: Did anyone ever try replacing strmatch with strcmp (or its siblings as needed)? I recall mlint...
  • jiro: @Daniel, We do use the hardware, but we don’t expose the supersampling feature through that path, so if...

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

Related Topics