Adding data from table into struct
1 view (last 30 days)
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
This is an example of a few rows from the table
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?
Image Analyst on 6 Feb 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.