How do I programmatically change the MATLAB Desktop current folder to the folder of an open script?

4 Ansichten (letzte 30 Tage)
I would like to put a command in my open script which changes the MATLAB current folder to the folder which that script is in. Is there a command that can do this?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 23 Nov. 2022
On MATLAB Desktop, adding the command below to a ".m" file (not a Live Script) and executing the script changes the MATLAB current folder to the folder of that ".m" file:
 
cd(fileparts(which(mfilename)))
On MATLAB Desktop, adding the command below to a Live Script (".mlx") and executing the Live Script changes the MATLAB current folder to the folder of that Live Script:
 
cd(fileparts(matlab.desktop.editor.getActiveFilename))

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by