Double for loop to read excel multiple excel spreadsheets
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have 45 spreadsheets (S01* - S45*) which each have data in 10 separate sheets (see attached example). Sheets 1-5 have 2x105 cells and sheets 6-10 have 3x105 cells. I simply want to read the data into the Matlab workspace as a cell array so that i can extract aspects of the data, mainly the numeric data, and package it up the way i need to.
After being a Matlab newb and reading lots on why I shouldn't try use the filename to dynamically name each iteration of the loop, the below code is an attempt to put it all into a cell array based on some previous matlab answers to similar problems. I want it to use filenames in BW_BW50files to be fed into second loop to extract the specific sheets of data.
for m = length(BW_BW50files);
[~,sheet_name] = xlsfinfo(BW_BW50files{m});
BWsheets = sheet_name(1:5);
%BW50sheets = sheet_name(6:10); % will be used on second run
for k = 1:numel(BWsheets);
BWdata{m}=xlsread(BW_BW50files{m},BWsheets{k});
end
end
My issue is it doesn't save each iteration for each subject in the cell array and I'm honestly not sure what the best approach to this problem is. I would be happy for them to be saved in a 45 x 5 cell array, where each row represents a subject and each column a sheet of data from the spreadsheet, however, don't know programmatically how to achieve this. This would then enable me to extract data from the cell array of each subject or groups of subjects.
Open to any changes in approach or suggestions for getting the data in by using a different data type.
Thanks in advance!
0 comentarios
Respuestas (1)
KSSV
el 10 de Jul. de 2018
filename = 'S01_BW_BW50.xlsx' ;
N = 10 ; % number of sheets
iwant = cell(N,1) ;
for i = 1:N
[num,txt,raw] = xlsread(filename,i) ;
iwant{i} = num ;
end
0 comentarios
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!