MATLAB Answers

How to get Matlab to reload an m file

50 views (last 30 days)
Mark
Mark on 17 Nov 2013
Commented: Walter Roberson on 18 Nov 2013
I'm trying Matlab for the first time. Since I prefer Emacs-like editors, I've been using an external editor on .m files. I was trying to find the source of odd bugs in my code, when in fact, Matlab was caching older versions of .m files. Finally exited Matlab and it loaded the correct files on restart. I should have realized sooner what was going on. Matlab is evidently not detecting that the files have changed, even though I can double click them in Matlab's "Current folder" window and see all the updates.
This then appears to be caused by an internal caching mechanism. Is there any way to tell Matlab to load the externally edited file?
MG
PS: The word "Matlab" is flagged by Mathworks' spell checker? :-)

Accepted Answer

Walter Roberson
Walter Roberson on 17 Nov 2013
If the function file name is YourFunction.m then
clear YourFunction
Note: Mathworks does not have a spell checker on the forum. Any spell checking is being done by your browser.
  2 Comments
Walter Roberson
Walter Roberson on 18 Nov 2013
It would be inefficient to go through the file system looking for files that might have changed. Therefore for efficiency it would be necessary to request for each file (or directory at least) that the operating system notify the program if the file (or directory) had changed. Unfortunately adding many sources to such a list is inefficient at the operating system level -- and MS Windows has relatively low limits on the number of watch handles that one can request.
There are circumstances under which MATLAB checks, but I do not recall what they are at the moment.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!