cannot find function even it is in path
53 views (last 30 days)
Show older comments
MATLAB is displaying the error message Unrecognized function or variable. I added the function file to one of the existing paths, but MATLAB still can't find it.
To resolve this, I need to reset the MATLAB path and add the path containing the function file again. Is this a common occurrence? I haven't encountered this before.
1 Comment
Answers (3)
Star Strider
on 5 Dec 2024 at 1:54
I am not certain what your problem is.
In my startup.m file, I have these assignments at the beginning:
pathmat = path;
My_Path = userpath;
My_Dir = My_Path;
My_Work_Dir = genpath(My_Dir);
addpath(My_Work_Dir, '-end');
I have not added any paths in the last few years, however when I have eartlier, this always added them to the existing path. I have never had any problems with this. You can check it later by running the path function.
You can then check with something like this:
p = path;
p = split(p, ';');
plast = p(end-10:end);
Hovering your mouse cursor over ‘p’ and ‘plast’ should bring up a tooltip that shows the contents of the respective variables, so you do not have to display the entire list in your Command Window.
.
0 Comments
Durga Lal Shrestha
on 5 Dec 2024 at 2:14
1 Comment
Star Strider
on 5 Dec 2024 at 2:49
Include the URL of this thread in your message to them so you do not have to repeat everything here.
Please post back here with their solution and your results using it.
Image Analyst
on 5 Dec 2024 at 4:16
If you try to run a script that is not in the current folder or on the path, it will popup a message prompting you to change the current folder to the folder where that file lives. You should do that and then it should run.
If that m-file calls another file that is not in that folder or on the search path, then you will get the message youi got. Make sure the folder where that other file lives is on the path by setting it's path with the Set Path button on the home tab of the tool ribbon.
If that doesn't work, type path in the command window and tell us what it says. Then tell us what the current folder is when you start running your m-file. And tell us what the folder is of the function it can't find (it must not be on the path even though you think it is). Are you sure you clicked the Save button when you added the folder to the path?
0 Comments
See Also
Categories
Find more on Startup and Shutdown 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!