Adding data from table into struct
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
I'm looking for a way to sum data in a table with data in a struct. The data in the table has to be matched with the data in the struct. I have data from a cognitive task stored in a 1x59 struct 'sFiles' (there were 59 subjects who completed the task). This task has 4 categories (original_11, original_12, original_21 & original_22), each with a timestamp of when it occurred (100 trials per category so a total of 400 trials per subject). The Subject IDs are listed under sFiles.SubjectName. In the script below, the 4 variables beginning with 'original' are each 1x100 doubles, extracted from struct sFiles, and contain the timestamps for each event for one subject. The timestamps within each one are listed sequentially in the 1x100 doubles, so first column is first trial, fifth column is fifth trial, etc.
The timestamps for these trials need to be corrected for a delay, so I need to add on a small amount of time to each one. This delay varies from trial/timestamp to trial/timestamp. I have the delay for each trial for each subject stored in a table 'T'. T.Subject has all subject IDs (400 rows for each subject), T.Conditions has the event category (11, 12, 21 & 22 (100 rows per category per subject)), T.Trial lists the number of the trial in each category (1-100) and T.Delay has all the delays that the 'original' in the struct has to corrected for (by summing them).
sFiles = bst_process('CallProcess', 'process_select_search', sFiles, [], ...
'search', '(([name CONTAINS "resample"]))');
for iFile = 1:length(sFiles)
DataMat = in_bst_data(sFiles(iFile).FileName);
original_11 = DataMat.F.events(1).times
original_12 = DataMat.F.events(2).times
original_21 = DataMat.F.events(5).times
original_22 = DataMat.F.events(6).times
end
This is an example of a few rows from the table
T =
Subject Conditions Trial Delay
"Subject008" 11 95 83
"Subject121" 12 96 84
"Subject156" 21 97 67
"Subject356" 22 98 67
Is there a way to match Subject, Conditions and Trials between the struct and Table so I can add the delays to the timestamps correctly?
0 comentarios
Respuestas (1)
Image Analyst
el 6 de Feb. de 2021
I didn't delve in your data (we don't even have any of it) or your code but you might want to look at grpstats() or splitapply() to do computations by groups. You might also find the functions vertcat(), struct2table(), table2struct(), or findgroups() useful.
3 comentarios
Image Analyst
el 7 de Feb. de 2021
Can you attach a small sample of the structure and table in a .mat file with the paper clip icon so we have something to work with? Make it easy for us to help you , not hard.
save('answers.mat', 'myTable', 'myStructure');
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!