I'm writing my first code with functions and I stuck. Please give me some advice.
1) general question. Now I'm using jEdit for my coding. Then when I want to test my code. I open the nrngui and using 'load hoc' to test my code.
However, whenever I made some change to my code, i have to quit() the nrngui, save my code(the editor do not allow me to save, I guess it is because the nrngui is using it) and open nrngui again then 'load hoc'.
I wonder is there better way to do that?(some command to 'unload' the hoc file)
Now the coding question. I want to measure the input-out relation of the cell. So I varied injected current and observe the firing rate.
Here is my code. Note that the 'singlecell.hoc' just contain the code for soma
Code: Select all
////// Current Injection and Spike recording /////////////
load_file("singlecell.hoc")
objref listAmp, listspk, f_means
listspk = new List()
f_means = new Vector()
listAmp = new Vector()
proc InjectRecord(){local stp,step,str,totalamp,j,i,idx
//Input $1 = start current amplitude
// $2 = step
// $3 = end current amplitude
str = $1
step = $2
stp = $3
// str = 0.0 //$1
// step = 0.01 //$2
// stp = 0.1 //$3
totalamp = (stp-str)/step+1
listAmp.resize(totalamp)
j=0
for(i=str; i<=stp; i=i+step){
listAmp.x(j) = i
j = j+1
}
f_means.resize(totalamp)
for idx = 0,idx <=listAmp.size-1{
injectI(listAmp.x(idx))
tmpspk =recordSpk()
listspk.append(tmpspk) //save spike train
f_means.x(idx) = f_mean(n_spk(tmpspk))
}
}
objref stim
soma stim = new IClamp(0.5)
proc injectI(){ //localobj stim
//Input $1 is current amplitude
//////// Iclamp ///////
//soma stim = new IClamp(0.5)
stim.amp = $1 //0.1 //amplitude
stim.del = 0 //delay
stim.dur = 500 //duration
}
obfunc recordSpk(){ local thre localobj vvec, tvec, spktrain
//////// record spike /////////
tvec = new Vector()
tvec.record(&t) // record time
vvec = new Vector()
soma vvec.record(&v(0.5)) // record v at 0.5 (center) of soma
spktrain = new Vector()
thre = -5 // the threshold for spikebin commonly used values are in the range -20 to +10 mV
tstop = 500
run()
spktrain.spikebin(vvec, thre) // Have to recall again every run() time
return spktrain
}
func n_spk(){ // $o1 is spktrain
return $o1.sum() // n spike
}
func f_mean() { // Input $1 = number of spike
//
return $1/tstop*1000 //spike per second
}
//InjectRecord(0,0.01,0.1)
I wonder what went wrong in my code.bad stack access: expecting (double); really (Unknown)
nrniv: interpreter stack type error
near line 4
InjectRecord(0,0.01,0.1)
^
InjectRecord(00.010.1 , , )
initcode failed with 1 left
It seems that the NEURON did not recognize the arguments as double. How could I do it?
Also, Is that the right way to declare variables as global variable?
Code: Select all
objref listAmp, listspk, f_means
listspk = new List()
f_means = new Vector()
listAmp = new Vector()
proc InjectRecord(){local stp,step,str,totalamp,j,i,idx
...