MATLAB: Does MATLAB 7.8 (R2009a) not recognize a function created at runtime unless the code contains a WHICH or EXIST command

bindingfoundfunctionMATLABnot

I have written a function "test1.m" which is calling another function "foo.m" that is created dynamically during runtime. foo.m will not be found since it did not exist on the path when binding the functions before execution.Consequently running test1 produces an error. However the example works when including a WHICH or EXIST command. It also works in debug mode.
Ignoring the fact this example is very questionable programming style I would expect that:
1. The behavior in debugging mode and normal execution mode should be the same.
2. It should be mentioned in the documentation that WHICH and EXIST do perform something like a "refresh bindings" callback.
function out=test1
fid = fopen('foo.m','w');
fprintf(fid, '%s\n', 'function out = foo');
fprintf(fid, '%s\n', ' out=''foo executed ''; ');
fclose(fid);
%if exist('foo.m','file'), disp('found foo'); end
%which -all foo
out=foo;
delete('foo.m');
end

Best Answer

The ability to use a function created at runtime is not available in MATLAB 7.8 (R2009a).
As a workaround you can use the REHASH command to update the MATLAB list of known files and classes for directories on the search path that are not in matlabroot/toolbox.