View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

3.0 | 2 ratings Rate this file 4 Downloads (last 30 days) File Size: 3.4 KB File ID: #29768 Version: 1.2



Jonathan Karr (view profile)


17 Dec 2010 (Updated )

Computes absolute path from relative paths

| Watch this File

File Information

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


Absolutepath.M inspired this file.

This file inspired Coverage Report Generator.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
18 Jan 2011 Jan Simon

Jan Simon (view profile)

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.

Comment only
12 Jan 2011 Jonathan Karr

Jonathan Karr (view profile)

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).

Comment only
12 Jan 2011 Jan Simon

Jan Simon (view profile)

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.

11 Jan 2011 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 []

11 Jan 2011 1.1

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

12 Jan 2011 1.2

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

Contact us