File Exchange

image thumbnail


version (3.4 KB) by Jonathan Karr
Computes absolute path from relative paths

1 Download

Updated 12 Jan 2011

View License

Computes absolute path from relative paths. Works on windows and linux. Improves on absolutepath from Jochen Lenz (

Cite As

Jonathan Karr (2019). absolutepath (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)


Dear Jonathan, Thanks for updating your submission. The program is much faster now!
I still cannot process the example from the help section:
absolutepath('A:\MyProject\', 'C:\local\');
I tried is as:
absolutepath('C:\WinXP', cd)
But get a "bad syntax for file name".
I think it is necessary to mention in the help section, that the file or folder must exist. And the important 3rd input should be explained also.

Thanks for the comments Jan. I completely departed from the original code I tried to patch from Jochen Lenz, and greatly simplified and sped the function per your suggestions. In my brief tests I find the new version is 10X faster (although still 5X slower than the mex file).


I cannot get it to work:
"cd('D:\Temp'); absolutepath('..')"
replies 'D:\Temp' instead of 'D:\'. "absolutepath('..', 'D:\Temp')" does not help also. "absolutepath('..\Temp')" does not work also. The documentation suggests, that "absolutepath('C:\WINXP', cd)" replies 'C:\WINXP', but the function stops with an error: "The path D:\Temp\C:\WINXP\ or file D:\Temp\C:\WINXP does not exist". For the same reasons, I cannot obtain the absolute path for e.g. "C:\WINXP\..".
The only valid results can be obtained, if a (nested) subfolder of the specified basefolder oder current directory is wanted.
"absolutepath('.', 'D:\')" replies 'D:', which differs from the correct 'D:\'.
The documentation is almost very good (H1 line, author, list of changes, syntax and examples), but the 2nd example 'A:\MyProject' seems to be unsolvable by the function (of course with an adjusted path name).
The function is rather slow: It needs 2.5 sec to convert the names of 837 M-files. GetFullPath from the FEX needs 0.05 sec for the same task.
Although the function is buggy, slow and works with a very limited sort of input, I really like the clear, simple and complete documentation and rate it with 3 stars.

Abel Brown

need to check that the path actually exists. You can not resolve the relative path for a file or directory that does not exist!

For example if im in /Users/myName and i call


your function returns


which is wrong. Should return either

No such file or directory or []


responding to Jan Simon's comments by greatly simplifying and speeding up by using methods

Per Abel Brown's comments adding optional error checking for absolute path of directories that don't exist

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: absolutepath.m

Inspired: Coverage Report Generator