Lab: Debugging

Created

Debugging


Errors

Types of errors

  • Syntax errors: violations of MATLAB grammar.
    • Typographical error: mispelling, missing parenthesis, undefined functions.
  • Semantic errors: program acts as instructed, but violates the programmer's intention.
    • Run-time errors: program ceases to execute
    • Logical errors: incorrect results

Debugging

The MATLAB Editor is a debug window.

Set Breakpoints to suspend execution at that line. When the execution stops, you can use the Command Window and Workspace Browser to inspect values.

After setting the break points, you can...

  • Step: execute the current line of the program
  • Step In: execute the current line, and if it is a function call, step into that function.
  • Step out: after stepping in, run the rest of this function or subfunction, step out and pause.
  • Continue: resume execution.

Examine values in

  • the Editor/Debugger
  • the Array Editor

Normal procedure:

  1. Prepare for debugging by settting breakpoints
  2. Running the M-File with breakpoints
  3. Step through the M-File
  4. Examine the values
  5. Correct the problems and end debugging by clearing the break points and saving.