how to load multiple files from directory into an array using matlab?
Show older comments
i have a directory that includes some .mat files , i want to load all these files into an array .
i tried something like this :;
x1=load('C:\Users\me\OneDrive\Desktop\project\a\first_file.mat')
x2=load('C:\Users\me\OneDrive\Desktop\project\a\second_file.mat')
... and so on for all the files in the directory , and at the end i want to have an array such that:
arr(1)=x1 ...
how can i access the directory and load all of the files at the same time into an array ?
ps: i tried using path before and dir but then i got this error :
> error using eval , undefind function 'workspacefun' for input
> arguments of type struct
thank you in advance.
5 Comments
Walter Roberson
on 9 Aug 2022
Is there exactly one variable in the .mat file, and it has the same name in each case?
Is it a numeric row vector? Numeric column vector? 2D? 3D?
molan
on 9 Aug 2022
Walter Roberson
on 9 Aug 2022
Are the variable names the same inside the file? Is there exactly one variable in the file?
Does it matter which order the entries go into the overall matrix?
Are there any .mat files in the directory other than the ones to be processed ?
molan
on 10 Aug 2022
Accepted Answer
More Answers (0)
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!