tags:

views:

442

answers:

4

Sometimes when I add a new file to my path, I have to restart MATLAB or it won't be detected. There must be an other way to this!

+3  A: 

I have experienced similar problems (Matlab does not notice it when I change a file). Unfortunately, I have no idea what causes it or how to solve it. I usually find that CLEAR ALL solves the problem, but be aware that it clears all variables in the work space. Some 'REHASH' command (e.g., REHASH TOOLBOXRESET) may also be useful.

I'd love to see a better answer; all documentation that I came across seems to indicate that this cannot happen.

Jitse Niesen
rehash or rehash('path') is sufficient if the files are not under the matlab/toolbox directory
Mike Katz
That's what the documentation says. However, I remember that once REHASH did not work while REHASH TOOLBOXRESET did, even though the files were not in the toolbox directory. Might well have been a coincidence, but since I've always used the latter option, since the cost seems to be very small (both commands return immediately).
Jitse Niesen
+2  A: 

Perhaps this is a problem with Matlab caching certain files at startup to improve performance. This happens with files in certain directories.

From Matlab help for path command:

Note (...) Also note that locations of files in the matlabroot/toolbox directory tree are loaded and cached in memory at the beginning of each MATLAB session to improve performance. If you save files to matlabroot/toolbox directories using an external editor or add or remove files from these directories using file system operations, run rehash toolbox before you use the files in the current session. If you make changes to existing files in matlabroot/toolbox directories using an external editor, run clear functionname before you use the files in the current session. For more information, see the rehash reference page or the Toolbox Path Caching topic in the MATLAB Desktop Tools and Development Environment documentation

groovingandi
+2  A: 

I've often seen this happen with networked file locations. I don't understand the mechanism, but it definitely happens. A solution that often works:

path(path);

or, if that fails to pick it up, try this: (NB, this will clear your workspace)

clear classes;
path(path);

We did this last one so much, we put it in script on our common code path called:

shazaam;

Yes, my age is showing.

Marc
+1  A: 

You want the "rehash" function or you need to set the path again using "path(path)" or similar. It also depends on whether you're using a "frozen" path. Look at the help for ADDPATH.

MATLAB will keep a cached copy of the compiled M-file unless it know that you've changed it. If you've created the file or you've edited it outside of MATLAB, then it may not know that it's changed.

Nzbuu