record from one cell of a matrix to a vector

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
oren
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

record from one cell of a matrix to a vector

Post by oren »

Hello,
how do I record a single cell of a matrix with python?

I know that if I want to record a Vector I can use the following code:

Code: Select all

Vvec = h.Vector()
Vvec.record(y0._ref_x[0])
But how do I record from a Matrix, as this does not work

Code: Select all

Vvec = h.Vector()
Vvec.record(c._ref_x[0][0])
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: record from one cell of a matrix to a vector

Post by ted »

oren wrote:how do I record a single cell of a matrix with python?
I'm not sure what you're asking. A matrix is an array of numbers. A model cell is not a number, so the phrase "a single cell of a matrix" has no meaning. Also, a cell is not a variable that changes with time, so what could it mean to "record" a cell? Are you saying that you created a bunch of cells that you are managing with array notation? That is, the name of any particular cell will be of the form
arrayname[j]?
I know that if I want to record a Vector I can use the following code:

Code: Select all

Vvec = h.Vector()
Vvec.record(y0._ref_x[0])
Close, but not quite right. Given a section called dend, the membrane potential at the 0.3 location of dend is called dend(0.3).v, and the way to record this voltage to a vector called Vvec is
Vvec.record(dend(0.3)._ref_v)
If some cell whose name is c[1][2] has a section called dend, then the way to record the voltage at c[1][2].dend(0.3) is
Vvec.record(c[1][2].dend(0.3)._ref_v)
oren
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

Re: record from one cell of a matrix to a vector

Post by oren »

Hello Ted,
Thank You for the respond.

Sorry for the confusion, I meant a single index in a hoc language matrix.

I want to record the values in a specific index in a matrix, as you can see here:
http://www.neuron.yale.edu/neuron/stati ... inmod.html

Code: Select all

...
nlm = h.LinearMechanism(callback, cmat, gmat, y, y0, b)


dummy = h.Section()
trajec = h.Vector()
tvec = h.Vector()
trajec.record(y._ref_x[0]) // here we record the values in the vector y
tvec.record(h._ref_t)
...
trajec Vector will record the values of the vector y.
But I want to know how to record values of an index in a matrix. ( specifically cmat in the LinearMechanism above... )

The problem is that this code:

Code: Select all

trajec.record(cmat._ref_x[0][0]) 
is not valid in python...

Thank You.
Oren.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: record from one cell of a matrix to a vector

Post by hines »

A limitation of the NEURON2PYthon interface is that element access of a hoc matrix from python cannot be done with the straightforward syntax, matrix.x[j] and one is forced to use
matrix.getval(i, j) and matrix.setval(i, j, val). An unfortunate consequence is that matrix._ref_x[j] is not a possibility.
The only work around I can think of for this case is to do the Vector.record from within hoc via a hoc wrapper function. i.e I think the following is sound
though I have not executed it so there may be typos.

Code: Select all

h('''
proc matrix_element_record() {
  $o1.record(&$o2.x[$3][$4])
}
''')

m = h.Matrix(3,3)
v = h.Vector()
h.matrix_element_record(v, m, 1, 2)
So some testing to make sure it works.
oren
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

Re: record from one cell of a matrix to a vector

Post by oren »

So there is not secret syntax to get the reference of a index in a matrix.. :-)

Thank you,
Oren.
Post Reply