How to import xlsx files after sorting files using sort_nat function?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Brian Ip
il 12 Apr 2016
Risposto: Walter Roberson
il 12 Apr 2016
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
0 Commenti
Risposta accettata
Walter Roberson
il 12 Apr 2016
[num,txt,raw] = xlsread(fNameOrder{m});
Question: why do you build the variable name but then do nothing with it?
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!