Open multiple excel files in loop
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Sean de Wolski
2014-12-11
编辑:Sean de Wolski
2014-12-11
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 个评论
Sean de Wolski
2014-12-11
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
2018-2-28
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!