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

 Respuesta aceptada

Joseph Cheng
Joseph Cheng el 19 de Mayo de 2015
Editada: Joseph Cheng el 19 de Mayo de 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))

Más respuestas (1)

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

Categorías

Más información sobre Search Path en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Mayo de 2015

Editada:

el 25 de Jul. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by