How to import xlsx files after sorting files using sort_nat function?

10 visualizaciones (últimos 30 días)
I am trying to import multiple xcel files into matlab in chronological order. For example, A1,A2,...,A12 instead of A1,A10,A11,A12,A2,...,A9. I use the dir function to obtain all of the excel files and then use sort_nat function to rearrange into chronological order. When I try to use xlsread to import files, I get an error saying "file name must be a string." What am I doing wrong? How can I make it work? My code is below:
fPath = uigetdir('.', 'Select directory containing XLSX files'); % the directory containing all CSV files to analyze
fNames = dir( fullfile(fPath,'*.xlsx') ); % CSV file info in the selected directory
fNameSort = {fNames.name};
fNameOrder = sort_nat(fNameSort)';
fDir = strcat(fPath, filesep, {fNames.name}); % cell contains all CSV file names
fDirOrder = sort_nat(fDir);
r = size(fNames,1);
for m = 1:r
xlsxFiles = dir(fDirOrder{m});
name = [];
name = xlsxFiles.name(1:end-5);
num = [];
txt = [];
[num,txt,raw] = xlsread(fNameOrder(m));
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Abr. de 2016
[num,txt,raw] = xlsread(fNameOrder{m});
Question: why do you build the variable name but then do nothing with it?

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by