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

조회 수: 35 (최근 30일)
Bob
Bob 2025년 11월 18일 15:31
댓글: Rik 2025년 11월 19일 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
Bob
Bob 2025년 11월 18일 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 2025년 11월 19일 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).

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by