フィルターのクリア

How to sequence series of excel files and extract certain rows:columns from each file automatically?

1 回表示 (過去 30 日間)
There are a series of excel files from 1 to 99, from file01.xlsx to file99.xlsx. I only want cells B1:C3 from each excel file. I used this code:
Efiles = dir('*.xlsx');
numfiles = length(Efiles);
mydata = cell(1,numfiles);
for k = 1:numfiles
myfilename = sprintf('file%d.xlsx',k);
mydata{k} = xlsread(Efiles(k).name);
end
Unfortunately, this extracts all the data from the excel file. I do not know how to utilize for loops to get the desired B1:C3 cells from each excel file.
Additionally, the workspace shows the extracted data as a cell array. How do you convert the cell array to regular array (matrix)? Otherwise, I can't use the data.
Thank you. (Sorry, MatLab beginner here, searched hours for answers, but struggling a lot).
<http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F > does NOT work in my case.

採用された回答

KSSV
KSSV 2018 年 9 月 26 日
files = dir('*.xlsx') ; % GEt all excel files in the folder
N = length(files) ; % total number of files
iwant = cell(N,1) ;
for i = 1:N
iwant{i} = xlsread(files(i).name,'B1:C3');
end
  2 件のコメント
John Gow
John Gow 2018 年 9 月 26 日
Thank you! It worked well, but how would I do this if I want to extract different cells within in Excel and import them?
For example, instead of B1:C3, I want A1:A3 and C1:C3.
By putting it in the iwant{i} line?
Image Analyst
Image Analyst 2018 年 9 月 26 日
Just pass it in to xlsread(). You can make up a string with sprintf() if you want:
cellReference = sprintf('A%d:C%d', row1, row2);
iwant{i} = xlsread(files(i).name, cellReference );

サインインしてコメントする。

その他の回答 (1 件)

John Gow
John Gow 2018 年 9 月 26 日
Thank you! I just relooped it.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by