5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[matlab] スクリプト実行ディレクトリを絶対パスで取得する

Last updated at Posted at 2018-09-23

pythonでの方法は知っていましたが,それのMatlab版をようやく見つけたので残しておきます。

fileparts(mfilename('fullpath'))

以下はテストコード。

test.m
fprintf("mfilename('fullpath')            : %s \n", mfilename('fullpath'));
fprintf("fileparts(mfilename('fullpath')) : %s \n", fileparts(mfilename('fullpath')));
実行結果
mfilename('fullpath')            : C:\Users\Ken\Documents\MATLAB\test 
fileparts(mfilename('fullpath')) : C:\Users\Ken\Documents\MATLAB 

なぜかファイルの拡張子が省略されます。詳細はmfilename関数のドキュメントを参照。昔調べたときはこの関数を見つけられなくて,Matlabではできないと思ってました。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?