"Undefined function or variable" when the directory is correct, and function is there!?

I'm having a frustrating issue with MATLAB, I'm very often getting an error - "Undefined function or variable" when calling a function, even though the function is either in the current directory, or I've added it's path. If I edit the function name, and try and call it with this new name it works!
Any suggestions would be fab, I've tried a few similiar questions, but have yet to find a solution..
Thanks

10 件のコメント

madhan ravi
madhan ravi 2019 年 4 月 26 日
what was your function name?
Jack Latham
Jack Latham 2019 年 4 月 26 日
this is a recent error that is occuring with many different functions
Walter Roberson
Walter Roberson 2019 年 4 月 26 日
Is it possible that you are storing the functions under the MATLAB installation directory?
Is it possible that the functions are stored on a network drive? Especially Windows 10 and Microsoft OneDrive ?
Jack Latham
Jack Latham 2019 年 4 月 26 日
Hi, no functions arn't being stored in the installation directory. The issue is happening in different directories. All functions are stored locally.
Jan
Jan 2019 年 4 月 26 日
Please post some examples for the working and not working file names. Use copy&paste, such that we can check if Unicode-characters are hidden in the names.
"If I edit the function name, and try and call it with this new name it works!" Then please explain in detail, when it does not work. How do you define the name initially?
Adam Danz
Adam Danz 2019 年 4 月 26 日
編集済み: Adam Danz 2019 年 4 月 26 日
Also, what's result of
which filename -all
where 'filename' is the name of your file (without file extension) ?
I'm having this same issue, and
which filename.m -all
prints
'filename.m' not found.
when I see it RIGHT THERE in the current directory.
Even
ls
shows the file to be visible and accessible.
Aaron Kaw
Aaron Kaw 2021 年 10 月 11 日
Okay, I just found out that the folder name my function is located in is named "resources" which MATLAB won't search in, and so won't know if you're trying to call a function name from there. I've renamed it to "res" which seems to work fine.
A clearer issue handling is done with folders with the name "aux" - MATLAB doesn't let you name a folder so.
Maybe Mathworks should provide some sort of warning when a folder by the name of "resources" or likewise is in your cwd?
Walter Roberson
Walter Roberson 2021 年 10 月 11 日
do you have any documentation on aux being a special folder to matlab?
https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html
I do not think that aux is special to matlab. I think that instead you are using MS Windows and are running into reserved file names for Windows
https://www.helpndoc.com/documentation/html/Windowsreservedfilenames.html
Steven Lord
Steven Lord 2021 年 10 月 11 日
As of release R2019a we no longer allow folders named resources on the MATLAB path, and you will receive a warning if you try to add such a folder to the path. Perhaps we should issue a similar warning if you try to make such a directory the current directory. I've made a note to discuss this with the relevant development team in the morning.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSearch Path についてさらに検索

製品

質問済み:

2019 年 4 月 26 日

コメント済み:

2021 年 10 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by