Matlab tries to use mex files not on search path

1 view (last 30 days)
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?

Accepted Answer

James Tursa
James Tursa on 12 Nov 2021
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 Comments
Kirsten
Kirsten on 12 Nov 2021
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 on 12 Nov 2021
@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:

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 12 Nov 2021
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 Comment
Kirsten
Kirsten on 12 Nov 2021
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.

Sign in to comment.

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!