実行しているファイルのパスの取得に関して

MATLABでmlxやmファイルを実行する際,そのファイルがあるディレクトリの場所に移動してから実行しようと考えております.
ディレクトリの移動には,
cd(PATH)
を使用すればよいことは分かるのですが,mlxやmファイルが存在する場所をどのように確認すればよいでしょうか?
また,cdコマンドは実行するmlxファイルやmファイルに記述することを考えております.

댓글 수: 1

madhan ravi
madhan ravi 2020년 7월 4일
Google translate:
When executing mlx or m file in MATLAB, I am thinking of moving to the location of the directory where the file is located before executing it.
To move the directory,
cd (PATH)
I know I should use, but how do I find out where the mlx or m files are?
Also, we are planning to write the cd command in the mlx file or m file to be executed.

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

 채택된 답변

michio
michio 2020년 7월 5일

0 개 추천

mfilename という関数がお役に立てるかもしれません。

댓글 수: 3

Teppei Iwata
Teppei Iwata 2020년 7월 6일
ご回答ありがとうございます.
mファイル上でご指摘いただいた関数を使用したところパスを取得することができました.
しかし,mlxファイル上で実行したところファイルのパスが取得できず,AppDataのディレクトリが与えられてしまいました.
このような時はどのようにすればよいでしょうか?
参考までにmlxでの実行結果を記載いたします.
mfilename("fullpath")
ans = 'C:\Users\X\AppData\Local\Temp\Editor_vxdxq\LiveEditorEvaluationHelperE1189016635'
よろしくお願いいたします.
michio
michio 2020년 7월 6일
検索してみると、他にもうまくいかないとの書き込みがあり、現状回避策はなさそうです。申し訳ございません。開発チームに改めてフィードバックいたしました。
ただ、以下の投稿の Example 2 は望みがありそうですが、非公式の方法であるのでご注意ください。
Teppei Iwata
Teppei Iwata 2020년 7월 7일
ご対応いただき誠にありがとうございます.
今後のバージョンに期待したいと思います.
また,当面の間はご教示いただいた,
tmp= matlab.desktop.editor.getActive
tmp.Filename
こちらの方法を利用させていただきます.

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

추가 답변 (1개)

Toshinobu Shintai
Toshinobu Shintai 2020년 7월 4일

0 개 추천

"which"というコマンドを使うと、そのファイルの場所を調べることが出来ます。
例:
>> which vdp
C:\Program Files\MATLAB\R2020a\toolbox\simulink\simdemos\simgeneral\vdp.slx

댓글 수: 1

Teppei Iwata
Teppei Iwata 2020년 7월 6일
ご回答ありがとうございます.
mlxファイル上で実行する際,自分のファイル名がわかる場合はこちらのコマンドでファイルのパスを取得できることを確認致しました.
ありがとうございます.

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

카테고리

도움말 센터File Exchange에서 ファイルの操作에 대해 자세히 알아보기

질문:

2020년 7월 4일

댓글:

2020년 7월 7일

Community Treasure Hunt

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

Start Hunting!