MATLAB Answers

kristau
0

Extracting columns from a matrix, corresponding start and end times

Asked by kristau
on 18 Mar 2019
Latest activity Answered by kristau
on 18 Mar 2019
Hi!
I am completely new to MATLAB, and I am having some difficulty. I have a 64x430250 matrix with EEG data, from which i need to extract all data corresponding to the latency events of interest. I have a vector (EEG.times, 1x430250) containing all the sampling times, vectors for the latencies of the different events themselves, and need to extract data from -200ms to 800ms around the event. I have also created vectors containing the start/end times for each of the variables if that should make anything easier. So if the startT is equal to EEG.times, extract the corresponding data in EEG.data (all rows, column startT:endT), and store it in a new variable (preferably a 3d matrix). I know I should end up with a 64x250x96 (as i know there are 96 events). Can someone help me?

  0 Comments

Sign in to comment.

2 Answers

Answer by Jos (10584)
on 18 Mar 2019
 Accepted Answer

The easiest approach is to create a for loop over the events
Nevents = nume(EventTimes)
R = zeros(64, 250, Nevents) % pre-allocation
for k = 1:Nevents
TF = EEG.Times > EventTimes(k)-200 & EEG.Times < EventTimes(k) + 800 ;
% TF should contain 250 true values!!!
R(:,:,k) = EEG.data(: , TF) ;
end
However, this will fail if there if for some events the number of samples within the time window is not the same ... You should think how you want to deal with these events.

  0 Comments

Sign in to comment.


Answer by kristau
on 18 Mar 2019

Thank you so much!

  0 Comments

Sign in to comment.