Aligning 5 second interval data of continuous time to the same interval

I have an array of times at which neurons are firing, spike times, that are all 5 second intervals. However, these intervals are increasing due to the data recording being done at the same time. Is there a way I can zero these five second intervals so that there time stamps are over the same time scale, say 0 to 5 seconds. Basically take 5 second intervals of time stamps from 16-21 seconds or 19-34 and 'zero' them from a 0 to 5 second scale. The attached matrix has an example of time stamps within some five second intervals. The overall goal is to overlay these spike times to look at the firing rate and density etc.
Any help would be greatly appreciated. Please let me know if I need to clear anything up.

 Accepted Answer

I’m not sure what you want to do. Your data are also not easy for me to interperet, because they lack a time base.
See if something like this works:
d = load('Heath Robinson spks.mat');
spk = d.spk;
for k1 = 1:size(spk,2)
thrsh = mean(spk{k1}(1:5)) + 5*std(spk{k1}(1:5)); % Define Threshold
dep(k1) = find(spk{k1} >= thrsh, 1, 'first'); % Initial Value Exceeding Threshold
end
figure(1)
plot([1:size(spk{1},2)], spk{1}, dep(1),spk{1}(dep(1)), 'r^')
hold on
plot([1:size(spk{2},2)], spk{2}, dep(2),spk{2}(dep(2)), 'r^')
plot([1:size(spk{3},2)], spk{3}, dep(3),spk{3}(dep(3)), 'r^')
hold off
grid

13 Comments

I have binned spike points, 0 for not firing and 1 for firing, along with the time stamp over the entire time window (binspikes)with intervals of start and stop times (intervals), not sure if that would be easier because it gives a time base.
I basically want the the five second intervals all starting relative to each other. These intervals happen periodically over the entire time of recording, but I want them all starting at time 0 relative to the interval start time.
Does this help?
I’m sorry, but I don’t understand your data.
I’ll delete my Answer in a few minutes, since I seriously doubt I’ll be able to help you.
I feel like its not too hard, I am just horrible at explaining it. I think it would be to just subtract the interval start time from the entire interval. So you set the start time to be time 0 and all spike times relevant to that.
The problem is that I have no idea what your data even represent.
The ‘binspikes’ matrix is a (114703x2) which I infer column 1 to be time and column 2 is something else.
The ‘intervals’ is a (3x2) douible matrix with no explanation.
I’m a Board Certified Internal Medicine physician (M.D.) and M.S. biomedical engineer, and I’m doing my best to help, as I do with most biomedical engineering Questions I encounter. But I still have no idea what you want.
My apologies for the confusion. I think I have figured out what I want to do, just do not have the coding experience to do it. The Intervals matrix left column is the start time of a behavior and the right column is the end time. The spks matrix is times of neurons firing that was sorted from a matrix containing all spike times of the neuron firing (spiketimes). Using the following code
if true
spiketimes=spiketimes' % just to visualise horizontally
[sz1_intervals sz2_intervals]=size(intervals)
% init containers of variable length for found spikes within each interval
for k=1:1:sz1_intervals
spk{k}={}
end
for k=1:1:sz1_intervals
w=intervals(k,:);
spk{k}=intersect(spiketimes(find(spiketimes>=w(1))),spiketimes(find(spiketimes<=w(2))));
end
end
So now all the spike times from the start and stop times of intervals are in a cell array. I would like to take the start time from the left column in the interval and subtract it from every spike time in its cell array. This will make all the interval times relative to 0. So basically for the first array take the first start time and subtract that time from within that cell array, the second from the second cell array etc.
I’ve been experimenting on and off with this for the past few days, and I still have no idea what you want to do.
It would probably help (if you feel comfortable discussing it here on MATLAB Answers) to describe your study, what data you collected, and what you want to demonstrate. I can’t figure it out from what you’ve written thus far.
Is it possible to just take the number in the right column and substract it from the entire cell array that it correlates with? The first row correlates with the first cell array, the second the second cell array and so forth?
If not I can go in more detail.
I’m not sure what to do with ‘spiketimes’. I assume from your most recent Comment you want to do something with ‘spk’ and ‘intervals’.
With this code:
d1 = load('Heath Robinson spiketimes.mat');
spkt = d1.spiketimes;
d2 = load('Heath Robinson spks.mat');
spk = d2.spk
d3 = load('Heath Robinson intervals.mat');
intvl = d3.intervals
This is what they return:
spk =
[1x84 double] [1x322 double] [1x140 double]
intvl =
60.1680e+000 65.1680e+000
88.2780e+000 93.2780e+000
105.5881e+000 110.5881e+000
What do you want to do with them?
The three spk matrices in the array correspond to each interval. So for the first matrix take the start time, 60.1680 and subtract it from every data point within the 1x84 double. The next start time 88.2780 and subtract it from the 1x322 double. 105.5881 from the 1x140 double.
I have to return them as a cell because their lengths aren’t equal:
out = {spk{1}'-intvl(1,1), spk{2}'-intvl(2,1), spk{3}'-intvl(3,1)};
This seems to be what you described.
Thank you! I can pad them once they are in cells, but thank you!
Could you put the code from "out" a way that could do it to more than just three sets of spikes and intervals?
I posted it as a question here:

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!