Attempting to change titles
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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
Walter Roberson
on 17 Dec 2019
Why are you overwriting all of GaitAnalysisTableNames each time through the loop?
Is the information stored in Data the correct size?
SheetNames(1,1:size(SheetNames,2)) is the same as SheetNames(1,:) which would pick out the entire first row of entries in SheetNames. However, SheetNames was read from xlsfinfo, which returns a cell array in the form of a row vector, so SheetNames(1,:) is the same as SheetNames . You are thus assigning the same
GaitAnalysisTableNames = SheetNames;
in each iteration of the loop; it is not obvious why you would do that.
Cameron Kirk
on 17 Dec 2019
Walter Roberson
on 17 Dec 2019
the subject in the loop has only 12 trials
What variable are you looking at to see that?
and the sheet number is overlapping each time
Which variable shows that to be true?
Cameron Kirk
on 17 Dec 2019
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)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!