How to load a .mat file from the parent directory?

6 ビュー (過去 30 日間)
Mr M.
Mr M. 2015 年 5 月 19 日
編集済み: Stephen23 2025 年 7 月 25 日
How to load a file which is in the parent directory of the running script?

採用された回答

Joseph Cheng
Joseph Cheng 2015 年 5 月 19 日
編集済み: Joseph Cheng 2015 年 5 月 19 日
you can determine your current directory with pwd.
so to load the file it'll go something like this
myfile = 'mymatfile.mat';
[parentdir,~,~]=fileparts(pwd);
load(fullfile(parentdir,myfile))

その他の回答 (1 件)

Stephen23
Stephen23 2025 年 7 月 25 日
編集済み: Stephen23 2025 年 7 月 25 日
Simpler and more efficient with a relative pathname using the dotdot-folder name to access the parent folder:
load('../mymatfile.mat')

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by