file not found in current directory

313 views (last 30 days)
craq
craq on 21 May 2018
Commented: craq on 25 Jul 2018
This sounds very similar to other entries in this forum and elsewhere e.g.
But a little different, and those answers don't help me. When I got this message the first time, I realised I had forgotten to copy a file across from a neighbouring folder. (I would hardlink if windows allowed that on network drives, or softlink if matlab could follow windows' softlinks... but I digress.) Even after copying the file, I still get the file not found message. Weirdly, 'edit my_function.m' works!
>> my_function
'my_function' is not found in the current folder or on
the MATLAB path, but exists in:
H:\path\to\nearby_folder
Change the MATLAB current folder or add its folder to the MATLAB
path.
>> exist('my_function')
ans =
0
>> which -all my_function.m
'my_function.m' not found.
>> edit my_function.m
>> ls
.
..
picture.png
figure.pdf
my_function.m
my_script.m
  4 Comments
craq
craq on 21 May 2018
Edited: craq on 21 May 2018
Yes, I altered the folder name and file names for privacy. But the function m-file is in the cwd, so the path shouldn't really matter. It is not in matlabroot.

Sign in to comment.

Accepted Answer

Cam Salzberger
Cam Salzberger on 21 May 2018
Hello Chris,
By default, MATLAB will cache functions and files for faster finding and executing of them. Generally files newly added to folders will be found properly, but sometimes it needs to be told to rehash before it will detect the new file. That it finds the file with edit and ls likely has more to do with those commands using a different system for finding files than the execution engine.
If rehash doesn't do it for you, try rehash toolboxcache just to be sure. Restarting MATLAB is something of the nuclear option here, but should work in almost all cases.
-Cam
  4 Comments
craq
craq on 25 Jul 2018
The first time was outside the matlab installation and outside the preferences directory. The second time I didn't record the directory I was in. It has only happened twice so far, so it's hard to talk about "reproducibility". If it happens again and I notice anything, I will contact tech support.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!