在MATLAB中查找当前m文件的位置 [英] Find location of current m-file in MATLAB
问题描述
我正在许多地方使用 MATLAB 代码,如果我可以使代码知道其在计算机上的位置,那将非常有帮助.我认为有一个功能可以为我提供准确的信息,但我不记得它的名字或在Google上找到它的原因.
I'm working on my MATLAB code in a number of different locations, and it would really help if I could make the code aware of its location on the computer. I think there is a function that gives me exactly this information, but I can't remember what it is called or find it on Google.
我的想法是我有一个函数myFunc
,该函数需要在其自己的目录中包含一个文件,该文件可以位于不同计算机上的不同位置.所以在myFunc
中,我想做这样的事情:
The idea is that I have a function myFunc
that needs a file in its own directory, which can be in different locations on different computers. So in myFunc
I want to do something like this:
dir = theFunctionImLookingFor;
system(fullfile(dir, 'someApp.exe'));
(也可能是我要查找的函数没有返回目录,而是目录+ m文件名,但这对我没有多大影响.)
(It could also be that the function I'm looking for doesn't return the directory, but the directory + m-file name, but that makes little difference to me.)