【发布时间】:2018-09-05 23:40:57
【问题描述】:
如果这看起来很明显,请原谅我,我对 R 很陌生。 因此,我试图获得看起来像向量 [1 0 1 1 0 0 0 1] 的随机 Spike Train,例如,我可以使用以下代码做到这一点:
fr = 100 #Firing rate of 100Hz
dt = 1/1000 #Short duration of time dt
nBins = 10 #10msSpikeTrain
x = runif(nBins) #Creating a "nBins" length string of random variable
#falling uniformly between 0 and 1
x
y<- numeric(nBins) # creating an empty vector of size nBins
MyPoissonSpikeTrain = function(x){
for (i in 1:nBins){
if (x[i] < fr*dt)
y[i]=1
else
y[i]=0
}
return(y)
}
#Creating a function that that returns its values in vector y as 1 if the
#spike was fired
#and 0 if the spike wasn't fired.
#Spike was fired, if randomly generated x value is smaller than fr*dt.
MyPoissonSpikeTrain(x)
这一切都很好,但我想创建一个矩阵,其中第一行将是上述过程的一个实例,第二行将是第二个实例,依此类推。
我希望这个过程发生(比如说)20 次,然后把我找到的每个单独的 y 作为一个更大的矩阵的一行,比如说 Y。我知道我需要将我的 y 修改为一个矩阵而不是一个向量,然后相应地修改我的 MyPoissonSpikeTrain 函数以使输出创建一个矩阵,但我不知道该怎么做。任何帮助将不胜感激。
【问题讨论】: