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
Best Answer