How can I add multiple excel files into a structure?
Afficher commentaires plus anciens
I am trying to save multiple xlsx files into one structure. Each xlsx file represents a jump (biomechanics data from VICON) and I need to organize my structure in a way that each jump is saved in the same structure ("Data{i}=[];"). The goal for this code is to analyze each jump and compare the same variables (i.e. Lkneemoments in the x direction, Lkneeforce in the z direction) between the different jumps for the same subject. Obviously I will have multiple subjects so I need to have some sort of a field where I am able to locate the different jumps of each subject.
The following code works for one excel file, however I need to be able to load the rest of my files located in the same folder as 'drop_jump.xlsx'.
[num,txt,raw] = xlsread('drop_jump.xlsx');
%%
[R,C] = find(strcmpi('Frame',raw)==1);
for i=1:length(R)
Data{i}=[];
IndStart=R(i)+find(num(R(i):end,1)==1,1,'first')-1;
IndEnd=R(i)+find(isnan(num(IndStart:end,1)),1,'first')-1;
if isempty(IndEnd)
IndEnd=size(num,1);
end
Data{i}.Frame=num(IndStart:IndEnd,1);
Data{i}.SubFrame=num(IndStart:IndEnd,1);
Label=raw(IndStart-2,3);
SubLabel=raw(IndStart-1,3);
Units=raw(IndStart,3);
for j=3:size(raw,2)
if ~isempty(raw{IndStart,j})&~isnan(raw{IndStart,j})
Units=raw(IndStart,3);
if ~isempty(raw{IndStart-1,j})
SubLabel=raw(IndStart-1,j);
SubLabel = erase(SubLabel,[" ","-",":","|","(",")"]);
end
if ~isempty(raw{IndStart-2,j})&~isnan(raw{IndStart-2,j})
Label=raw(IndStart-2,j);
Label = erase(Label,[" ","-",":","|","(,",")"]);
Data{i}.(Label{1})=[];
end
Data{i}.(Label{1}).(SubLabel{1})=num(IndStart:IndEnd,j);
end
end
end
Any sort of help or feedback is much appreciated.
3 commentaires
I would strongly suggest this is NOT the way to organize your test results for ease of analysis by subject and/or other independent variables.
I'd recommend creating a single table (using the MATLAB readtable function) in which you append the files and incorporate a variables that are the subject ID and observation number for the action. Then use those as grouping variables with rowfun and/or perhaps groupsummary and I'll bet the analysis results will just fall into your lap...
It would be far simpler to try to help with an example data file to work with -- use the paperclip icon to attach.
Leutrim Mehmeti
le 10 Août 2022
dpb
le 10 Août 2022
Wowsers!!! That IS a complex workbook, indeed! It'll take a whole lot of parsing to make anything useful out of that structure, indeed -- although I still don't think burying it inside another structure is likely to be of a lot of help even if you get it stuffed into one.
I guess some sort of generic idea of what needs to be done with the data might help to design a data structure although indeed, when one has multiple cases of same variable the need for the variable names to be unique is somewhat of a disadvantage with table. But, they've still got to be unique in any other format as well -- or just not named and referenced by indices. There might be where a struct or a table inside a table(*) might be and advantage.
(*) Indeed, one can, in fact, have a column variable in a table be another table -- there might be the way to handle the various types. Or, there could be an array containing the types.
I've got another commitment just now; I'll try to look at the spreadsheet in some more detail later on...
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!