Change working directory to where the mlx file is saved

I have an mlx file which is run from different computers and I would like to automatically change the working directory to the directory in which the file is stored in (maybe with pwd??).
That is, I have identical copies of the mlx file which are run either from computer 1 or computer 2 (there are actually a lot more users involved, this is just an example):
In computer 1, the mlx files is stored in say this folder:
c:\user\comp1\docs
In computer 2, it is here:
c:\user\comp2\docs
Is it possible to run a command that identifies the folder that the mlx file is stored in, and then CD into that folder?

Respuestas (1)

If that folder is in the matlab's path, you can
which your_mlx_file.mlx

3 comentarios

Thanks, but this prints out the name of the folder including the name of the file, so I cannot CD into that folder. Is it possible to get an output that I can use subsequently for the CD command?
Where = which(mfilename)
cd(fileparts(Where))
Excellent!!! Thank you so much Walter and Yongjian!!!

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 29 de Nov. de 2021

Comentada:

el 29 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by