Possible duplicate:
Find the location of the current m file in Matlab
I would like to write an m file that displays the directory in which the function is defined.
For example, if the function foo.m is placed in the directories c: \ bar and c: \ foo (the full path to the file is either c: \ bar \ foo.m or c: \ foo \ foo. M), none of which not inside MATLAB path, this sequence of commands
addpath("c:\bar"); foo
will produce the result: I am located in the c: \ bar directory
a
addpath("c:\foo"); foo
will lead to a result. I am located in the c: \ foo directory
How can I write such a function?
source share