How to match trial number to time stamps given two sets of data?
1 view (last 30 days)
I have a set of data with time stamps every couple of milliseconds that I need to add a trial number to using another set of data that gives me the onset of the trial. What I would like to do is add a column to the time stamped data that gives the trial number for each sample taken. The data that gives the trial onset has columns for the cue onset, stimulus onset, and response time. I would like to measure the trial from the cue onset to the next cue, and then add another column that indicates where in the trial this occurs.
For example, say A is my timestamped data (A in practice would have other columns with unrelated variables) and B is the table that indicates when these occur. The column in A is just the time stamp. The columns for B are- B(:,1)=cue (when I want the trial to start), B(:,2)=stimulus onset, B(:,3)=when the response occured
I would like to get a table (call it C) where the columns would be C(:,1)=timestamp from A, C(:,2)= trial number, C(:,3)=where in the trial the stamp is. C for this would look like:
I want the trial to start at cue onset and then end at the next trials cue onset. C(:,3) would indicate where in the trial the stamp is so that 0 could be from cue and stimulus onset, 1 could be from stimulus onset to response, and 2 could be from response time to the next cue.
My table also has some time stamps from before the first trial cue, so I was also wondering if there was an easy way to get rid of the timestamped data before this first cue?
Thank you for any help!!
Eric Sofen on 19 Aug 2021
Assuming your timestamps are durations (you probably want A to be a timetable with duration row times), you can use the isbetween function.
whichTrial = isbetween(A,B(:,1)',[B(2:end,1)', inf]);
whichTrial is now a logical array, with each column representing the trial and each row corresponding to the timestamps in A. Then use find to
[~,trial] = find(whichTrial);
A.trial = trial;
You could then do something similar for the information that you illustrated in C(:,3).