Reading Multiple CSV Files in a Sequence
Mostrar comentarios más antiguos
I wrote a code to read and process 55 csv files.
The first step was to read the data and save it in a cell structure in away that each csv file would be saved in a cell a table:
d=dir('*.csv'); % list all csv files in working directory
n = length(d); % number of files in the directory
tempdata=cell(1,n); % preallocate a cell array to hold results
for i=1:n
tempdata{i}=readtable(d(i).name); % read each file
end
I expected that the 1st. csv file will be stored in tempdata{1,1}, 2nd in cell tempdata{1,2}, etc.. but I noticed that:
tempdata{1,1} = file1.csv
tempdata{1,2} = file10.csv
tempdata{1,3} = file11.csv
.
.
tempdata{1,12} = file2.csv
.
.
How can I change the sequence of saved files so:
tempdata{1,1} = file1.csv
tempdata{1,2} = file2.csv
tempdata{1,3} = file3.csv
.
.
tempdata{1,10} = file10.csv
.
.
tempdata{1,55} = file55.scv
Appreciate the time and efforts that you put to answer this question.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Files and Folders 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!