Why are changes to MATLAB files that are located on a network drive not seen until I clear the function?

1 view (last 30 days)
I am using MATLAB on a PC running Windows XP, and my machine is connected to a network. When I create a new MATLAB file in the 'current directory', (when this is a network directory) while MATLAB is running, MATLAB does not recognize the file.
When I do the following:
1. Map a network drive.
2. Run MATLAB locally.
3. Change directories to the network drive I just mapped.
4. Create a new MATLAB file and save it on the same network drive. (current directory)
5. Run the MATLAB file in MATLAB by typing its name at the prompt.
For some reason MATLAB will not recognize the file.
6. I then use the CLEAR function and this doesn't help.
7. If I add the current directory to the path with the command:
addpath(cd)
the function is now seen.
8. Now I update the file I just created and saved in the network drive, but MATLAB does not recognize the changes.
9. I must type "clear all" or "clear function_name" for the changes to be seen.
However, on my external drive, MATLAB sees the function the first time I create it, but it will not see any changes unless I clear the function.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2013
This results from a performance problem. MATLAB often has so many files in directories added to the path, that if it were to read each file every time a function was called, it would run very slowly. This problem is exacerbated by the slow speed of file systems, especially network file systems. Due to this, MATLAB stores the files in the system cache memory. However, doing so leaves the problem of detecting changes to each directory. We use Windows Change Notification Handles (CNH) on Windows to detect these changes. CNHs tell MATLAB when a directory changes so that the directory can be reloaded into memory. CNHs are used because file timestamp checking is too slow.
There are a limited number of CNHs on Windows Systems. When they run out, MATLAB can not detect changes in network directories reliably. This may cause MATLAB not to detect recent changes to a MATLAB file. There are several options for freeing or increasing the numbers of CNHs are available. There are related solutions that provide more information about CNHs.

More Answers (1)

Jonathan
Jonathan on 1 Apr 2016
Edited: MathWorks Support Team on 6 Apr 2018
Please see this link for a potential workaround: https://groups.google.com/forum/#!topic/comp.soft-sys.matlab/S1JSUN_Xz3Q

Categories

Find more on Search Path in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!