Open multiple excel files in loop

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!

 採用された回答

Sean de Wolski
Sean de Wolski 2014 年 12 月 11 日
編集済み: Sean de Wolski 2014 年 12 月 11 日

2 投票

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 件のコメント

Ellen
Ellen 2014 年 12 月 11 日
This worked, but I'm not really sure how to pull data from cells within cells within cells.
Sean de Wolski
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
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 件)

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

質問済み:

2014 年 12 月 11 日

コメント済み:

2018 年 2 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by