Dear Ted,
I have started using this program very recently, and I would like to ask you about a particular piece of code doesnt work.
I have been implementing McIntyre's axon (from the model DB) and I have created a program to store the potential values of each node (the axon has 21 nodes) in a matrix, to export it to a data file and process it in matlab. However, when I write this in a loop, it does not work, and I do not want to run the program 21 times, because that is computationally inefficient. I am therefore copying 2 pieces of code.
1. This one does not work.
objref recv,m,savdata
recv= new Vector()
m= new Matrix()
savdata= new File()
for i=0,20{
recv.record(&Mcaxons.node.v(0.5))
m.resize((recv.size()+1),20)
m.setcol(i,recv)
}
tstop=105
run()
savdata.wopen("matrixv1.dat")
m.fprint(savdata, "%g")
savdata.close()
2. If I put the run() command before recv.record(...) it does not record anything. Why does this happen?
3. If I dont loop things my program works, why is this?
objref recv,recv1,recv2,m,savdata
recv=new Vector()
recv1=new Vector()
recv2= new Vector()
m= new Matrix()
savdata= new File()
recv.record(&Mcaxons.node[0].v(0.5))
recv1.record(&Mcaxons.node[1].v(0.5))
recv2.record(&Mcaxons.node[2].v(0.5))
tstop=105
run()
m.resize((recv.size()+1),3)
m.setcol(0,recv)
m.setcol(1,recv1)
m.setcol(2,recv2)
savdata.wopen("matrixv.dat")
m.fprint(savdata, "%g")
savdata.close()
Could you kindly suggest a better way of coding this? Thank you.
query export data into matrix
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: query export data into matrix
Good questions. Clean looking code. You're already close to the right answers.
It is also important to read and re-read the documentation, especially after one's code does not work as expected. No matter how many times I have read a particular passage, an unexpected outcome often means that yet one more reading is needed to improve my understanding.To quote from the Programmers' Reference documentation of Vector record
You have the right idea about assembling the recorded Vectors into a Matrix, then writing the Matrix to a file. But the assembly can only be done after the Vectors contain data (otherwise, you'll be assembling a bunch of empty Vectors into a Matrix that will have no elements). Do it after you call run().
The documentation of the Matrix class's setcol method says
m.resize((recv.size()+1),20)
will make the matrix one row too long.
Of course you should check to make sure I haven't made one of dozens of possible errors (typographical, "off by 1", syntax . . .)
While it is essential to have a clear conception of what a completed program should do, it is also essential to develop incrementally, testing at every step, especially when writing code in an unfamiliar programming language. And never more so than when one is already familiar with another programming language (did I guess correctly?), because of a phenomenon similar to what linguists call "false friends" (http://en.wikipedia.org/wiki/False_friends).Nuri wrote:1. This one does not work.
It is also important to read and re-read the documentation, especially after one's code does not work as expected. No matter how many times I have read a particular passage, an unexpected outcome often means that yet one more reading is needed to improve my understanding.
Code: Select all
for i=0,20{
recv.record(&Mcaxons.node[i].v(0.5))
. . .
So each pass through the loop breaks what the previous pass did. If you want to record from N nodes, you will need N Vectors.vdest.record(&var)
. . .
DESCRIPTION
. . .
Previous record and play specifications of this Vector (if any) are destroyed.
You have the right idea about assembling the recorded Vectors into a Matrix, then writing the Matrix to a file. But the assembly can only be done after the Vectors contain data (otherwise, you'll be assembling a bunch of empty Vectors into a Matrix that will have no elements). Do it after you call run().
The documentation of the Matrix class's setcol method says
but this statementThe vector must have size msrcdest.mrow
m.resize((recv.size()+1),20)
will make the matrix one row too long.
To quote again from the documentation of Vector record():2. If I put the run() command before recv.record(...) it does not record anything. Why does this happen?
This means that they only occur during initialization and when the simulation advances from one time step to the next, i.e. only during a simulation. run() executes a simulation.Transfers take place on exit from finitialize() and on exit from fadvance().
You need a good way to manage recording from many nodes. One way is to use an "array" of objrefs, e.g. something like thisCould you kindly suggest a better way of coding this?
Code: Select all
// define important constants near the top of the program, so they're easy to change in the future
NUMNODES = 21
. . .
// set up Vector recording
objref recv[NUMNODES]
for i=0,NUMNODES-1 {
recv[i] = new Vector()
recv.record(&Mcaxons.node[i].v(0.5))
}
. . . whatever else you need to do before launching a simulation . . .
run() // runs the simulation
// now there are data to be written to a file
// assemble the records into a matrix
objref m
m = new Matrix(recv[0].size(), NUMNODES)
for i=0,NUMNODES-1 {
m.setcol(i, recv[i])
}
// ready to open a file and write the matrix to it
. . .
Re: query export data into matrix
Many thanks for your helpful reply! It works now.
I am also implementing different ways of counting action potentials. You mentioned that NetCon is a more powerful method than APcount in a different wall post.
Why is this?
I am also implementing different ways of counting action potentials. You mentioned that NetCon is a more powerful method than APcount in a different wall post.
Why is this?
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: query export data into matrix
The NetCon class's record method captures the time of each spike.Nuri wrote:I am also implementing different ways of counting action potentials. You mentioned that NetCon is a more powerful method than APcount in a different wall post.
Why is this?
http://www.neuron.yale.edu/neuron/stati ... tml#record
-
- Site Admin
- Posts: 6300
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: query export data into matrix
Thank you for using NEURON in your research.