MATLAB: Does Matlab has an internal cache for files

buginternal cacheMATLABwrong datazombie files

Hi all, i have the following issue. To check some code I have written in C++, i write the c++ data into a file that is called foo.m. In this file there is only one variable set, like "x= [1;2;3];". When i run foo.m in matlab it executes the script and writes the variable to the workspace. But as I run different tests, i delete the file foo.m, run the c++ code and the new foo.m is given.Now to my issue: When I delete the file foo.m, I can still execute the script for some time, even if it is not there. Additionally, when the new foo.m is given it sometimes still calls the old foo.m and loads that data. This can be seen when looking at variable x and into foo.m. Whsy does this happen?
To note: I am using Ubuntu 14.04 and Matlab R2012b.
Does anyone has an Idea why this happens and how to clear the "cache"? Is this a bug? Or is there a "zombie" file which matlab internally puts the data? I already tested pressing F5 to update the file list.

Best Answer

Yes, Matlab does cache functions on first execution. Use
clear yourfunctionname
to remove the previous version from memory.
doc clear % for details