Info

This question is closed. Reopen it to edit or answer.

Attempting to change titles

1 view (last 30 days)
Cameron Kirk
Cameron Kirk on 17 Dec 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello,
I'm trying to create a for loop through data, to read data from various sheets within matlab, however it keeps on overlapping using the following code:
for j=1:size(ExcelFilePatients,1)
% 1.2 GaitAnalysisReport: read and rearrange all sheet numbers
[~,SheetNames] = xlsfinfo(ExcelFilePatients(j,1).name); %Sheet Names
nSheets = length(SheetNames); %Sheet lengths
index=1;
for i=2:nSheets
Name =SheetNames{i};
sheetData = xlsread((ExcelFilePatients(j,1).name),Name);
Data{j,index} = sheetData(5:end,:);
index=index+1;
GaitAnalysisTableNames = SheetNames(1,1:size(SheetNames,2));
end
end
Some of my subjects have different amount of sheets (due to more/less trials), The most sheets I have is 28, so sheets names needs to be a 1,28 cell.
Sheet names is getting overlapped in each loop, so it reads as only a 1x12 cell, as the last subject in the loop has only 12 trials.
How do I please stop this overlapping?
  5 Comments
Cameron Kirk
Cameron Kirk on 17 Dec 2019
Sorry,
There are 11 subjects in the loop alltogether
subject 1 for example has 28 trials,
subject 11 has 12 trials
This is contained afterwards in the 'Data' variable, which displays a blank [] where the empty trials are the subjects
Walter Roberson
Walter Roberson on 17 Dec 2019
There are 11 subjects in the loop alltogether
To confirm, you mean that size(ExcelFilePatients,1) is 11 ?
subject 1 for example has 28 trials,
I take it that each sheet is a different trial?
You discard the first sheet for each file, so I am not sure whether the first file would have 28 sheets of which you would store 27, or if the first file would have 29 sheets, of which you would store 28 ?
What is size(data) after the code? When I look at the code, I expect it would be a cell array that is 11 x 28, and that for row 11, entries 13 to 28 would be [] . Are you seeing something different than that? Do you need something different than that? For example perhaps you should be using
Data{j}{index} = sheetData(5:end,:);
so that Data would be a cell array vector with 11 elements, and each of the elements would be a cell array containing the number of elements that matches the number of trials ?

Answers (0)

Community Treasure Hunt

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

Start Hunting!