Hi,
I am trying to load data from 12 Excel Documents into matlab. Each Excel document contains a varying number of sheets, with the first sheet of every document named 'Summary' and then the sheets are named Trial1, Trial2, Trial3 etc…. Some documents go up to 29 trials, others only 20.
I am struggling now, as I need to loop through automatically and access the sheets one at a time.
The loop here is first looping over all of my subjects, which it does correctly.
In the second loop, first I create a 1×29 cell (SheetNames), that contains all of the names of my sheets. Now I'm trying to use my index (iSheetData) to access the sheet name that corresponds to 1 in my SheetName cell on the first iteration which is the summary sheet, then 2 on the second iteration which is Trial1 etc…. the loop index will change everytime and mean that I will access the next sheet on the next loop. I am now stuck on this with the message:
Error using readtable (line 216)Sheet name '({SheetNames}.(iSheetData}' does not exist or is not supported. Tocheck if the sheet is supported, specify the sheet by its worksheet index.
If someone could please help!
DirectoryPath_Project = 'M:\Work Packages\WP2\Task 2.1.2 - Data UNIBO\Standardization\EPFL\EPFL Data-Rewire-Stroke\Original'; % folder to the project's data
cd(DirectoryPath_Project)FilePatients = dir(DirectoryPath_Project); % Patient1,Patient2,Patient3,Patient4,Patient5,Patient6,Patient7,Patient8,Patient9,Patient10,Patient11,Patient12
ExcelFilePatients = dir( '*.xls');FilePatientsSize = size(FilePatients,1);% Other directories
DirectoryPath_Standardized = 'M:\Work Packages\WP2\Task 2.1.2 - Data UNIBO\Standardization\EPFL\EPFL Data-Rewire-Stroke\Standardized';%Create loop over all subjects
for iExcelSubject = 1:size(ExcelFilePatients,1); GaitReport = ExcelFilePatients(iExcelSubject).name; %loads gait file
[~,SheetNames] = xlsfinfo(GaitReport); %Takes all sheet names from the excel document
nSheets = size(SheetNames); for iSheetData = 1:nSheets SheetData = readtable(GaitReport,'sheet','({SheetNames}.(iSheetData}'); endend
Best Answer