merging files using for loop
Mostrar comentarios más antiguos
I am trying to merge 7 text files into 1 using system ('copy 090615.txt+090616.txt+090617.txt+090618.txt+090619.txt+090619.txt+090620.txt+090621.txt New.txt'); How can I do the same thing using a for loop. Thanks
Respuesta aceptada
Más respuestas (1)
Calling the operating system is indirect. You can do this inside Matlab instead:
Folder = cd; % Set accordingly
Str = '';
for k = 90615:90621
FileName = fullfile(Folder, sprintf('%06d.txt', k));
Str = [Str, fileread(FileName)];
end
newFile = fullfile(Folder, 'New.txt');
fid = fopen(newFile, 'w');
if fid == -1, error('Cannot open file for writing: %s', newFile);
fwrite(fid, Str, 'char');
fclose(fid);
1 comentario
MF
el 19 de Mzo. de 2016
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!