Thursday, May 26, 2011

Getting started with Matlab

  1. Matlab has a very good reference and help system in itself. To get started, these sections in Matlab documentations can be very helpful.
    • "MatLab", "Image Processing Tool Box", and "Statistics Tool Box".
  2. This book can be very good if one is planning to use Matlab with image processing.
    •  Digital Image Processing (3rd Edition) by Rafael C. Gonzalez and Richard E. Woods
  3. To program in Matlab, there are two things to be aware of. First the program should be easy to understand. Second the program should be modulated. To achieve these two goals, listed below are a few programming tips.
    • Use comments to explain the purpose or give a big picture of programs.
    • Use meaningful variable names such that the program can be understood with little comments.
    • Give each constant parameter a descriptive name.
      • For example, write
        • >> descriptive_name = 1;
        • >> a_function(descriptive_name);
      • but not,
        • >> a_function(1);
      Write relatively short functions instead of long scripts.
      Each function is designed to achieve one goal only.
      If two functions repeats simily works in part, extract that part to a function.
      Organize the functions and put them in a subfolder of the src/ directory.
      • Your directory tree will look like
        • src/
          • src/module1/
          • src/module2/
          • ...
    Matlab has very good tools for debugging, testing and profiling. Please checkout these tools in Matlab and use them often. For convenient programming and testing, here are some more tips.
    • During initial programming/testing, we can write in one test script file. Then we use the cell mode to run only part of the programs for detecting and correcting errors.
    • The values of the variables can be examined in you desktop by switching to workspace. 
    • If there is really some illusive error, we can use the debugging tool for further testing.
    • After the initial testing is finished, each segment of the program will be extracted to a function.
    • Test the function again to correct any errors.