How to get Matlab to reload an m file

23 views (last 30 days)
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
Mark
Mark on 18 Nov 2013
Thanks, Walter. I knew of the 'clear' function, but only in context of cleaning up workspace variables. It didn't register that it would be useful for compiled functions as well (just checked Matlab help). In fact, I hadn't realized that there was a compiler and caching system.
It seems like it would be useful for Matlab to be able to auto-detect when an .m file has changed and do the recompile next time it is run. (Lots to learn, so maybe there's a reason why that isn't done)
Understood about the spell-checker. Given that the editing is done in-place on the Mathworks site, I thought the vocabulary was supplied by Mathworks.
Anyway, thanks. That was a quick reply! M
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)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!