How to import xlsx files after sorting files using sort_nat function?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brian Ip
le 12 Avr 2016
Réponse apportée : Walter Roberson
le 12 Avr 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 commentaires
Réponse acceptée
Walter Roberson
le 12 Avr 2016
[num,txt,raw] = xlsread(fNameOrder{m});
Question: why do you build the variable name but then do nothing with it?
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!