MATLAB Answers

0

Error after moving function .m file: 'Previously accessible file "...\z_estimate.m" is now inaccessible'

Asked by Tom Horton on 22 Aug 2019 at 15:58
Latest activity Commented on by Tom Horton on 23 Aug 2019 at 8:39
Having created a function file "z_estimate.m" and successfully called the function (from the command line), I noticed I had inadvertently saved the file in the top-level MATLAB folder instead of the subfolder "my_functions", which is also on my Matlab path. So, I dragged the .m file from the top level into the subfolder, in the Matlab filemanager window. Now when I call that function I get the error
Previously accessible file
"...\MATLAB\zestim.m"
is now inaccessible.
In an attempt to diagnose the issue, I used "Save as..." to save a copy of the function as "z_estimate2.m" (and changed the function name to "z_estimate2"). When I call z_estimate2, it works. But I don't want my function to be called that if possible, and in future I don't want to have to rename functions if I move them.
I tried using "restoredefaultpath" from the command line and then re-adding "my_functions" to the path, but the original function won't run. If I move it back to "MATLAB" it works fine, however, I don't want all my functions in the top-level folder, I would like to be able to organise them into subfolders.
For information, I am running Windows 7. I found another question about this error, to which the answer referred to changing system TEMP variable, so mine is:
%USERPROFILE%\AppData\Local\Temp
How can I move a function file between two folders that are both on the Matlab path and still be able to call them?

  0 Comments

Sign in to comment.

1 Answer

Answer by Jan
on 22 Aug 2019 at 18:13
Edited by Jan
on 22 Aug 2019 at 18:13

"saved the file in the top-level MATLAB folder instead of the subfolder "my_functions", which is also on my Matlab path"
This sounds like you store user-defined functions inside Matlab's installation folder. This is a bad idea, because the files inside Matlab's installation folder are cached. You can get more troubles with this also.
Although there is a solution to recreate the hash whenever you modify a file:
rehash toolboxcache
this is time-consuming. So use the standard way to store your files anywhere else.
By the way, you need admin privilegs to write in the program folders. Working with admin privileges is a bad idea also. 1. this reduces the security level massively, 2. you can modify Matlab's toolbox functions by accident. You can find threads in this forum concerning this problem. It is extremely hard to debug. Remember: A modified file is not refreshed in the memory automatically. So if you destroy a toolbox function, this has effects only after the next restart of Matlab.
For a stable and reliable system:
  • do not work with admin privilegs
  • do not store user-defined function inside Matlab's installation folder matlabroot.

  2 Comments

If you move one of your own files that is not inside an installation directory and there is a @ handle to it, then matlab will not automatically fix up the location. In this situation, "clear" the function name and recreate the @ handle
If you have the editor open to a file and move it then the next time you visit the file in the editor it will complain about the file being inaccessible. In this case just open it in its new location.
If you move a file that you are in the middle of debugging then you will probably have trouble and will probably need to quit debugging.
Solved
Thanks Jan and Walter. The problem was solved by restarting Matlab. Sorry I didn't try that before, guys.
For the sake of others with a similar problem:
The "MATLAB" folder I refer to in the question is actually a folder in "My Documents" (\\metdc.metrasens.local\users\tjhorton\Documents\MATLAB) which I presume the installer created specifically for user defined functions and scripts. The installation directory is separate from that (C:\Program Files\MATLAB\R2019a). Plus, I do not have administrator priviledges.
With reference to Walter's comment: I can open the file just fine in the editor, from the new location. However, the error still occurs when I try to call the function (I'm calling it from the command line). I may have had the file open in the editor when I moved it, but I wasn't using the debugging features.
I am not using an @ handle.

Sign in to comment.