Brethlosze
Brethlosze

Reputation: 1618

Matlab - Path to the Current Script

Under any two years recent version of MATLAB, I am looking for the path of the current script being executed (ref.1, 2, 3, 4, 5),

Let's say, for a script through any of the following user procedures, in general, when a user runs a script:

User procedures that could not be accepted by the solution, because there would be no associated script, are:

User procedures out of the scope of the question related to functions, which could be solved easily through any of the following indicated solutions, is:

This is not for a function, which is trivially done through any of the following alternatives:

mfilename
mfilename('fullpath') 
which(mfilename)
which('mfilename')
S = dbstack('-completenames');S(1).file
[folder,name,ext] = fileparts(which('object'))

And this is of course not the same that requesting the current folder through:

cd
pwd

Upvotes: 3

Views: 1863

Answers (1)

matlabgui
matlabgui

Reputation: 5672

edit I misunderstood the question initially...

So with hopefully a bit better understanding you could try and utilise:

matlab.desktop.editor.getActiveFilename

to get the current active file in the editor -> which should give the current script...

Note: this is an undocumented function which may change between releases -> it gives me the active filename in r2015b.

Upvotes: 5

Related Questions