open some .mat files (whose names are saved inside a cell)
5 views (last 30 days)
Show older comments
Hi! I need to open some .mat files (whose names are saved inside the 'name_cell' cell).
I tried this way but, of course, it saves them all with the same name, overlapping them.
load name_cell.mat
folder = pwd;
for K = 1:height(name)
% Load file .mat
file = load(fullfile(folder,name{K,1}));
file = file.original_name; % all files are originally named 'original_name'
end
I would like to open them all with that specific name inside 'name_cell'.
Also, I need to save those open files in a single cell, like this:
matrix_cell = [{file_1};{file_2}];
0 Comments
Accepted Answer
Stephen23
on 7 Aug 2023
Edited: Stephen23
on 7 Aug 2023
Where C is your cell array of filenames, and assuming exactly one array is saved in each MAT file:
D = C;
for k = 1:numel(C)
S = load(C{k});
D{k} = S.original_name;
end
4 Comments
Stephen23
on 8 Aug 2023
"But I need to read the .mat files from a 'folder' other than pwd."
Provide the absolute/relative filepath and use FULLFILE:
P = 'absolute or relative filepath to where the files are saved';
D = C;
for k = 1:numel(C)
F = fullfile(P,C{k});
S = load(F,'original_name');
D(k) = struct2cell(S);
end
More Answers (0)
See Also
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!