Matlab tries to use mex files not on search path

1 次查看(过去 30 天)
I am having troubles with Matlab trying to call mex versions of functions instead of the regular functions with the same name (within an external toolbox) and then telling me that the mex files are invalid. Strangely, this happens even when the mex files in question are not at all on the search path. When I type "which functionname" I get the path to the correct (non-mex) version of the function. But when that function name is called from the script I get the error. The same scripts with the same path settings worked just fine up until a week or so ago. I tried resetting to the default path and renaming the matlab.prf file to reset all preferences to defaults. No change in behaviour. Could anyone please let me know how to get Matlab to look for functions based on the search path order rather than prioritising those with mex extension?

采纳的回答

James Tursa
James Tursa 2021-11-12
You should use debugging to find out why this is happening. Type the following at the command line:
dbstop if error
then run your code. When the error occurs the code will pause at that point with all variables and settings intact. At that point you can use 'which' and 'path' to find out what the situation is and why your code is getting confused.
  2 个评论
Kirsten
Kirsten 2021-11-12
Oh my I'm an idiot. I went through it line by line and one of my functions changes the path. Thank you both for your help!
Image Analyst
Image Analyst 2021-11-12
@Kirsten glad you found the problem - using cd. As the FAQ says, using cd() is almost never necessary. Maybe it's time to re-read all of the FAQ now to learn of other goodies that may help you avoid problems in the future:

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2021-11-12
When you call DLLLoadLibrary you can put the full path (folder + base file name + extension). How did you load/register the mex/DLL file and how did you call it?
  1 个评论
Kirsten
Kirsten 2021-11-12
Thanks! To the best of my knowledge, I didn't call the mex file at all. I just want to use the regular functions that happen to have the same name as some mex files. I put the toolbox folder on the path, but not the subfolders that contain the mex files. This has been working just fine for years, but I must have messed with some setting unintentionally since then.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by