Change working directory to where the mlx file is saved

조회 수: 9 (최근 30일)
Metin Akyol
Metin Akyol 2021년 11월 29일
댓글: Metin Akyol 2021년 11월 29일
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?

답변 (1개)

Yongjian Feng
Yongjian Feng 2021년 11월 29일
If that folder is in the matlab's path, you can
which your_mlx_file.mlx
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 11월 29일
Where = which(mfilename)
cd(fileparts(Where))
Metin Akyol
Metin Akyol 2021년 11월 29일
Excellent!!! Thank you so much Walter and Yongjian!!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by