-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpruneMex.c
31 lines (24 loc) · 897 Bytes
/
pruneMex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "mex.h"
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *spikes, *samples, *values, maxLag;
int iiSpike, iiSample, iiLeft, nSamples, nSpikes;
spikes = mxGetPr(prhs[0]);
samples = mxGetPr(prhs[1]);
maxLag = *mxGetPr(prhs[2]);
nSpikes = mxGetM(prhs[0]) * mxGetN(prhs[0]);
nSamples = mxGetM(prhs[1]) * mxGetN(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(mxGetM(prhs[0]),mxGetN(prhs[0]),mxREAL);
values = mxGetPr(plhs[0]);
iiLeft = 0;
for(iiSample=0; iiSample<nSamples; iiSample++) {
while(iiLeft<nSpikes && spikes[iiLeft]<samples[iiSample]-maxLag) {
iiLeft++;
}
for(iiSpike=iiLeft; iiSpike<nSpikes && spikes[iiSpike]<samples[iiSample]+maxLag; iiSpike++) {
values[iiSpike] = 1;
}
}
}