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

5 visualizzazioni (ultimi 30 giorni)
How to load a file which is in the parent directory of the running script?

Risposta accettata

Joseph Cheng
Joseph Cheng il 19 Mag 2015
Modificato: Joseph Cheng il 19 Mag 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))

Più risposte (1)

Stephen23
Stephen23 il 25 Lug 2025
Modificato: Stephen23 il 25 Lug 2025
Simpler and more efficient with a relative pathname using the dotdot-folder name to access the parent folder:
load('../mymatfile.mat')

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by