Aug 16, 2013

Top 10 Productivity Tools in Matlab

Rick Rosson is a Senior Applications Engineer at Mathworks, a company that developed the Matrix Laborary (Matlab) software. He gave a talk on top ten productivity tools in Matlab, most of which I already knew. Still, I liked the talk because I got a free Matlab logo sticker for answering correctly to a question he posed during the talk (Yay!).

Here is the list of top ten productivity tools in Matlab according to Rick Rosson (not in any particular order though).
  1. Code Analyser
  2. Section Mode
  3. Publishing
  4. Command History
  5. doc command
  6. Tab completion
  7. Inline syntax guidance
  8. Automatic variable name change
  9. Matlab path
  10. startup.m
You can read about all the above ten tools from Mathworks website, however, let me give you a brief introduction to each of the tools.
Code Analyser: This is a new feature in Matlab which you will find at the top right corner of Matlab editor window. If your script is error free, the code analyser indicator will turn green indicating everything is alright. If your code is inefficient, or has error which does not affect the execution of the code, it turns yellow. As you would have probably guessed by now, the code analyser indicator turns red if there is any error in your script that affects the execution of the code.

Section Mode: As a Matlab user, you would have probably known that '%' symbol at the beginning of a line is used to comment a sentence. Instead, if you use '%%' symbol, it will still work as comment, but in addition, it starts a new section. So if you are writing a code which can be split into several sections (or modules), you can separate them by using '%%'. For example, you can have a section to read or import the data, another section to analyse the data and one more for making plots.

Publishing: One useful feature about Matlab is its ability to publish a report in the form of pdf or html or in many other formats. Traditionally, I execute each plot, save them as jpg or eps format and manually add/import results to create a presentation file or a report in word format. All these can be done now at the click of a button. What more? The comment tag that you type followed by the '%%' symbol will become section header when you publish!

Command History: Had a bingo moment when you created that plot some time ago, but struggling to find how did you create it later on? Command History comes to your rescue in such situations. As the name suggests, the command history windows remembers all the commands you had every typed since the last time you cleared the history manually. You can even select a portion of history and make a script out of it.

doc command: While help command gives you a rough idea of what the function is about, doc command will give you more details and insight of the function. In other words, doc gives you a complete documentation about a function which you want to learn how to use.

Tab completion: This, I think, probably came from working in a Linux environment. Its probably useful when you are creating a Matlab script that runs to 1000s of lines. To speed up writing a code, type first few characters of a command (typically two to three characters) and then hit Tab command to autofill, or to choose the right command from a list of options.

Inline syntax guidance: You probably have an idea of name of a function that you want to use, but not sure about its syntax? Don't worry. Just type the function name and wait for fraction of a second. The inline syntax guidance will pop up with a help window showing various syntax options by which the function can be called.

Automatic variable change: Suppose if you have written a function for a specific problem. And now, you want to generalize it by changing specific variable name such as 'temp' to more general variable name, such as 'x'. You have probably done this using find and replace tool. But the catch is that there could be several variables starting with temp, for eg, tempoutside, temproom. Find and Replace would probably do a nasty work (if you do try, you will get xoutside, xroom instead of general variable names such as x1, x2 etc). Automatic variable change does this job more efficiently. Just change the variable name 'temp' to 'x', hold the Shift Key and hit Enter button. It will search and replace only the variable name 'temp'.

Matlab path: addpath command adds the path to custom library folder where users can create and save custom library files specific to their work. By default, Matlab would search for a function in the current directory. In case the current directory does not have the function file, addpath will tell Matlab where to search for it.

startup.m: Instead of using addpath command every time you open a new session in Matlab, you can write a startup script and set all the paths. Matlab would execute the startup script every time it is started, and automatically add paths to various custom libraries and functions.

In addition to the top ten productivity tools, Rick also listed ten more productivity tools. They are
  1. tic toc
  2. profiler
  3. file compare
  4. todo fixme
  5. debugger
  6. stack browser
  7. plot browser
  8. plot tools
  9. generate script
  10. file import wizard.
Thanks to audience's frequent interruptions and their effort to make this talk "An introduction to Matlab", Rick did not have time to discuss about these ten tools. But then, we have Google right?