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

6 vues (au cours des 30 derniers jours)
Mr M.
Mr M. le 19 Mai 2015
Modifié(e) : Stephen23 le 25 Juil 2025
How to load a file which is in the parent directory of the running script?

Réponse acceptée

Joseph Cheng
Joseph Cheng le 19 Mai 2015
Modifié(e) : Joseph Cheng le 19 Mai 2015
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))

Plus de réponses (1)

Stephen23
Stephen23 le 25 Juil 2025
Modifié(e) : Stephen23 le 25 Juil 2025
Simpler and more efficient with a relative pathname using the dotdot-folder name to access the parent folder:
load('../mymatfile.mat')

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by