Skip to main content
Engineering LibreTexts

14: Debugging Directory Errors

  • Page ID
    96724
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

      Users sometimes correct code errors, but the code still does not run. While this often happens when there are more than 1 errors or when the correction is either not correct or not complete. But sometimes the correction is complete and the new code is fine, but the code still does not run. 
      Here are some possible causes and solutions.

      1. When you have 2 files (a test script and the original script or function), in order for the test script to call (run) the original script or function, both of those files need to be in the working directory (folder). (The words "directory" and "folder" are synonyms in this text.)
      1.a. You need to know which directory is being used by the MATLAB or Octave workspace. When you first install Octave or MATLAB, the default directory may be in the Octave or MATLAB directory. You should create a separate directory under "documents" for each course or project.
      Then you need to change your your workspace to use that directory. See sections 2.1 or 2.2 on how to change the directory you are operating in.

      You can check which directory is being used either by looking at the path above the command window or entering this command: pwd (=print current working directory).

      1b. By default, the editor is likely storing your files in the downloads directory or in the C:\Documents directory. In the editor, you use "save as" to save the code files in the directory for your course or project.

      2. A second problem is that after you correct errors, it is possible that Octave or MATLAB still remembers and uses the older version. This seems to happen more often with Octave, but it can happen with MATLAB, too. You can test if it is running your old code or your new code by adding an extra line of code such as xyz = 123. If that does display, then it is running the new code. If that doesn't display, then an older version of the code is being run.

      There are 2 possible solutions to this.
      2a. The easiest thing is to make sure the file is saved before you run it. But this may not solve the problem.
      2b. The surest thing to do is to use "clear all". This not only clears any variables, but it also clears any references to files you were using. Then when you rerun your code, it will use the current version.

      Of course, you may still have actual errors that need correcting.


      This page titled 14: Debugging Directory Errors is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Carey Smith.