How to combine multiple .dat files.

24 visualizaciones (últimos 30 días)
Ahmed Alsaadi
Ahmed Alsaadi el 21 de Nov. de 2018
Comentada: Image Analyst el 11 de Abr. de 2022
I have 5 files (.dat) that are 2x20 (row,col) I want to import them and combine them in one file, the new file should (10x20)

Respuesta aceptada

Image Analyst
Image Analyst el 21 de Nov. de 2018
Just call csvread or dlmread 5 times, then concatenate, then call csvwrite
m1 = csvread(filename1);
m2 = csvread(filename2);
m3 = csvread(filename3);
m4 = csvread(filename4);
m5 = csvread(filename5);
mOut = [m1;m2;m3;m4;m5];
csvwrite(fileNameOut, mOut);
  3 comentarios
Katey Faber
Katey Faber el 11 de Abr. de 2022
Editada: Katey Faber el 11 de Abr. de 2022
Is there an easy way for use a for loop with this method to csvwrite() hundreds of files?
Image Analyst
Image Analyst el 11 de Abr. de 2022
You can use a for loop
outputFolder = 'c:\whatever';
if ~isfolder(outputFolder)
mkdir(outputFolder);
end
for k = 1 : 200
data = GetNewDataSomehow();
baseFileName = sprintf('File #%2.2d.csv', k)
fullFileName = fullfile(outputFolder, baseFileName);
writematrix(data, fullFileName);
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Biological and Health Sciences 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!

Translated by