Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do MATLAB functions know which directory they are defined in? [duplicate]

Tags:

matlab

Possible Duplicate:
Find location of current m-file in Matlab

I would like to write an m-file that will display the directory the function is defined in.

For instance if the function foo.m is placed in the directories c:\bar and c:\foo (full path to the file is then either c:\bar\foo.m or c:\foo\foo.m), neither of which is intially on the MATLAB path, this sequence of commands

addpath("c:\bar");
foo

would produce the result: I am located in directory c:\bar

while

addpath("c:\foo");
foo

would produce the result I am located in directory c:\foo

How can I write such a function?

like image 384
Marc Avatar asked Feb 24 '23 16:02

Marc


1 Answers

Are you looking for the mfilename function? The optional fullpath input argument returns the full path to the m-file that the function is called from.

like image 72
Praetorian Avatar answered May 18 '23 19:05

Praetorian