Why did MATLAB load a function from an unexpected m-file?

35 views (last 30 days)
Bob
Bob on 18 Nov 2025 at 15:31
Commented: Rik on 19 Nov 2025 at 14:36
I'm running MATLAB 2018a. (Yeah, I know. Corporate IT.)
I have an m-file that pulls in functions from several other m-files.
Yesterday, I ran into a problem because the function that was pulled in and ran was not the function I wanted or expected.
Specifically, my main function runs a function called instrRack. This function is defined inside an m-file named instrRack.m.
I expected to get the instrRack function from the file C:\git\unified-cryo\unified\Instruments\@instrRack\instrRack.m.
Instead, the instrRack function came from the file C:\git\unified-cryo\adr\Instruments\@instrRack\instrRack.m
I discovered this by digging through the error stack returned by the use of the incorrect instrRack function.
Note that the correct file is "unified-cryo\unified" while the incorrect file is "unified-cryo\adr".
I don't believe I've seen this problem before and I've been using my main function for months, if not years.
As far as I could tell, my MATLAB path was correct. Specifically, C:\git\unified-cryo\unified was at the top of the path, with C:\git\unified-cryo\unified\Instruments a few entries below that.
Unless I missed something, C:\git\unified-cryo\adr was nowhere in the MATLAB path.
Other people use MATLAB on the same test stand. Could one of them have used a path that included the incorrect m-file, and that incorrect m-file or path somehow persisted into my MATLAB session?
I tried killing and restarting my MATLAB session several times, each time verifying that my MATLAB path was correct. However, I kept getting the function from the wrong m-file.
I wound up having to restart the PC in order to get the function from the correct m-file.
Any suggestions on why I kept getting the function from the wrong m-file?
  3 Comments
Bob
Bob on 18 Nov 2025 at 17:13
Thanks! Given the extremely intermittent (i.e. never before seen) nature of this problem, any debugging will have to wait until this is seen again. However, you've given me some things to check as well as some things to try.
Rik
Rik on 19 Nov 2025 at 14:36
which('instrRack','-all')
can also help a lot in figuring out which functions shadow which call. The full list can provide a lot of information you weren't expecting (especially when things go wrong).

Sign in to comment.

Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!