How to sequence series of excel files and extract certain rows:columns from each file automatically?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
John Gow
el 26 de Sept. de 2018
Respondida: John Gow
el 26 de Sept. de 2018
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.
0 comentarios
Respuesta aceptada
KSSV
el 26 de Sept. de 2018
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 comentarios
Image Analyst
el 26 de Sept. de 2018
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 );
Más respuestas (1)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!