Docsity

Debugging Techniques and Common Errors in Matlab, Study notes of Computer Science

Partial preview of the text

Download Debugging Techniques and Common Errors in Matlab and more Study notes Computer Science in PDF only on Docsity!

Dr. John Cavazos Computer and Information Sciences 04/10/

๏‚— Common Errors ๏‚— Debugging Tips (pgs 72 โ€“ 76) ๏‚— Symbolic Debugger (137-140)

๏‚— Not initializing all variables ๏‚— Starting array index variable at 0 ๏‚— Incorrect evaluation order in equation ๏‚— Off by one error ๏‚— Infinite loop

๏‚— Break up equation into smaller pieces ๏‚— Add parenthesis to make equation clear ๏‚— Initialize all variables!

Finding an number in array

  • Pass into function array and number
  • Initialize array index to 1
  • Initialize number found boolean variable
  • while number not found
  • if current array position has num
  • set number found
  • end
  • If number found report!

Finding a number in an array

function found = findNumber(array, value) x = 1; found = false; while (found == false) if (a(x) == value) found = true; end end What is the problem?

Add some print statements

function found = findNumber(array, value) x = 1; found = false; while (found == false) if (a(x) == value) found = true; end x = x + 1; end Problem if value not found! Should test for this.

Add some print statements

function found = findNumber(array, value) x = 1; found = false; while (found == false && x <= length(a)) if (a(x) == value) found = true; end x = x + 1; end

๏‚— Execution suspends in editor at breakpoint ๏‚— Can view variables in command window ๏‚— Can step through the code ๏‚— Can continue to next breakpoint 17, 2009 from 1:00 PM to 1:30 PM