open some .mat files (whose names are saved inside a cell)
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2023-8-7
编辑:Stephen23
2023-8-7
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 个评论
Stephen23
2023-8-8
"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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!