Open multiple excel files in loop
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have about 100 excel files that are all LiFePO4-KAU-3_Cha_01 with consecutive numbers.
I tried setting up a for loop like I saw multiple suggestions of as follows:
for i=03:51
C{i}=xlsread('C:\Documents\Battery\LiFePO4-KAU-3_Cha_%d.xlsx');
end
But it gives me an error and says the file is not found.
I tried some other methods that I found via google also, but I kept getting errors with those too.
Any help on this would be immensely helpful!
0 Commenti
Risposta accettata
Sean de Wolski
il 11 Dic 2014
Modificato: Sean de Wolski
il 11 Dic 2014
Here's a similar example that I have:
% Copyright 2014 The MathWorks, Inc.
% Automating File Import
% Select folder containing data interactively
Location = uigetdir;
% Identify where to search for files
% Store the name of all .xls files as a vector D
D = dir([Location, '\*.xlsx']);
% Extract the file names
filenames = {D(:).name}.';
data = cell(length(D),1);
for ii = length(D):-1:1
% Create the full file name and partial filename
fullname = [Location filesep D(ii).name];
% Read in the data
data{ii} = xlsread(fullname);
end
3 Commenti
Sean de Wolski
il 11 Dic 2014
Use {} braces. You don't need to store it as a cell, you could use a table or a struct instead. Tables are good for tall columns so that could be a good thing to try. Personally, I use cells for import and then deal with the cell after for converting it to whatever format I need.
olahan
il 28 Feb 2018
Mr. de Wolski. I apologize beforehand for my stupidity, but I am encountering a similar problem. I wanted to do something similar, so I found this thread and I hope you do not mind that I ask a question here.
I used your code written above and it works brilliantly; however, I want to pull data out from the data cell using a for-loop. All my excel files are configured the same way, so I would like to, for example, pull out the data for cell 5,2 and the range 1:11,4 in data(1), data(2), et cetera.
I guess you already answered this question with your comment about {} braces, but I am a bit lost about the correct syntax.
Thank you.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB 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!