import to the workspace a .mat file saved in a folder other than pwd

1 view (last 30 days)
How can I import a .mat file saved in a folder other than pwd to the workspace?
folder = 'C:\Users\Desktop\folder_test';
file = 'test.mat';

Accepted Answer

Stephen23
Stephen23 on 22 Jul 2023
Edited: Stephen23 on 22 Jul 2023
The recommended approach is to use FULLFILE (and to always LOAD into an output variable):
S = load(fullfile(folder,file))
Why do you imagine that this has changed since last time you asked how to define path strings?:

More Answers (1)

Bruno Luong
Bruno Luong on 22 Jul 2023
Edited: Bruno Luong on 22 Jul 2023
folder = 'C:\Users\Desktop\folder_test';
file = 'test.mat';
load([folder filesep() file])

Categories

Find more on Filename Construction in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!