# Calculating StdDev for elements of a matrix

3 views (last 30 days)
Nicholas Woodruff on 12 Sep 2019
Commented: Nicholas Woodruff on 13 Sep 2019
I am working on a project evaluating blink rate differences over the course of a 5minute recording session. I would like to have matlab segment the data into 3 second bins and output a sum of blinks occuring in each 3sec bin. From there I would like to calculate the standard deviation for the entire set. I will include an example text file containing the matrix I will be working with and discuss some specific issues that I am aware of.
Portion of text file:
Tmu Code TriNo Comnt
297983 1 101 Pattern 1
303657 1 100 Pattern 1
1073645 1 100 Pattern 1
1084329 1 101 Pattern 1
2329000 1 1 Trigger - DIN6
2524582 1 101 Pattern 1
2543130 1 100 Pattern 1
For my purpose, only the Tmu and TriNo columns are relevant. Time units are seconds*10^-5, and the TriNo "100" represents a blink. One thing to point out is that time units are only recorded at the time point when an event occurs (TriNo). This lead to issues with my first idea, which was to have the script start at 0 and look for 300000 (3sec) in Tmu and add 1 to some variable set to 0 for every instance of "100" in TriNo across that time period. Since neither of these time units actually exist in the matrix this approach has not been successful. I would appreciate any tips on how to approach this issue. I am a fairly new matlab user, and this relatively simple issue has me pulling out my hair. Thanks in advance.

David Hill on 12 Sep 2019
Assume you can load column vectors Tmu and TriNo of the same length from your table into matrix T where first column is Tmu and second column is TriNo. Assign constants for startTime and finishTime (might be Tmu(1) and Tmu(end).
for i = startTime+3e5:3e5:finishTime
s=sum(T(:,1)<=i);
T=T(s+1:end,:);%eliminates the top of T as it is processed
end

#### 1 Comment

Nicholas Woodruff on 13 Sep 2019
Thanks! With some slight modifications this solved my problem. I appreciate the help.