MATLAB: Avoiding use of cd to resolve filenames

file io cd

I am losing a lot of time in my code in a subfunction of the memmapfile constructor which resolves the pathname of the file in question. The code (copyright 2004-2006, The MathWorks, Inc.) has the following:
oldDir = cd(directory);
resolvedName = fullfile(cd(oldDir), [basename extension]);
A profile confirms this consumes an unacceptable amount of time (as compared to just calling resolvedName = fullfile(directory,[basename extension])
Does anybody have a workaround? I was thinking just calling the naive fullfile, then checking for existence of the file (via fopen, say), and falling back to the double cd code above.
BTW, this is from Matlab 2007a. Perhaps TMW has fixed this in newer releases…

Best Answer

I would think that will be faster too. For checking the existence of the file, use exist(...,'file') must be faster than using fopen().
See this post for some encouragement, but again "swim at your own risk".