MATLAB lessons

Doing a ton of MATLAB coding these days. What an amazing tool. For a numbers geek, this is so much better than Excel. The macro language in excel/spreadsheets has always been wacky, and the basic tool in later versions is even worse.

MATLAB is awesome but of course some key lessons that I am relearning, as well as some new ones.

  • Off-by-one errors are killers. Especially when dealing with huge complex matrices. Document and layout your variables carefully.
  • The lack of any variable typing system is a little scary, as well as the lack of required variable declarations. You can get in a lot of trouble easily by declaring variables willy-nilly and doing whatever you want with them. Powerful but a little dangerous.
  • OK, the ability to create variables with the same name as built-in values/functions, and/or the ability to assign values to built-ins without regard to their intended value — well this is just nutso.  And the “lint” tool that is part of the development environment doesn’t make a peep about it. For instance, I used “i” as the index value for a loop. Unfortunately “i” means of course the square root of -1, and when you arbitrarily set this to say 5, bad $h!t happens. Who ever thought it was a good idea to let users do this? Lesson learned.
  • MATLAB is very PL/1 like. OK this doesn’t mean much to most people, but there is a function or library for everything in MATLAB. If it is something you want to do, there is probably already a function or option to do it, you just have to sift thru the function reference to find it.
  • BTW, make sure you change the help search options to span just the libs you have access to. Otherwise everytime you search help, you will get 95% useless information.
  • The lack of even the most primitive source control package in the development environment is ridiculous. It is easy to point the tool at other working directories tho. Short of installing a source control system , clone your working directory often. Really there ought to be some simple versioning in the tool and the ability to rollback.