필터 지우기
필터 지우기

Double for loop to read excel multiple excel spreadsheets

조회 수: 1 (최근 30일)
Jamie Hetherington
Jamie Hetherington 2018년 7월 9일
답변: KSSV 2018년 7월 10일
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!

답변 (1개)

KSSV
KSSV 2018년 7월 10일
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

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by