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

7 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by