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

조회 수: 11 (최근 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 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