Convert all csv in a folder to .mat
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elise Barbeau
el 3 de Feb. de 2021
Comentada: Jan
el 5 de Feb. de 2021
I have several csv files in one folder and I want to convert them all to .mat format?
Is it possible to do that at once?
0 comentarios
Respuesta aceptada
Jan
el 3 de Feb. de 2021
Editada: Jan
el 4 de Feb. de 2021
Folder = 'D:\YourFolder';
FileList = dir(fullfile(Folder, '*.csv'));
for iFile = 1:numel(FileList)
% [TYPO FIXED]: [name, ext] ==> [~, name, ext]
[~, name, ext] = fileparts(FileList(iFile).name);
data = readtable(fullfile(Folder, [name, ext]));
save(fullfile(Folder, [name, '.mat']), 'data');
end
10 comentarios
Jan
el 5 de Feb. de 2021
This suggestion does it during the creation already. Then you do not have to do it again. But the code looks similar to the one of my answer:
Folder = 'D:\YourFolder';
FileList = dir(fullfile(Folder, '*.mat'));
for iFile = 1:numel(FileList)
FileData = load(fullfile(Folder, FileList(iFile).name));
data = FileData.data;
data(1, :) = [];
save(fullfile(Folder, [name, '.mat']), 'data');
end
Más respuestas (0)
Ver también
Categorías
Más información sobre String Parsing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!