return double array

The basics of how to develop, test, and use models.
Post Reply
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

return double array

Post by oren »

I can not mange to return a double array.
My code is :

Code: Select all

double CC[2]
double cc1[2]
    func go(){

cc1 = go()
print cc1[0]
print cc1[1]
But all I get is that cc1[0] = 1 and cc1[1]=0

How can I pass all of the array with the return?

Thank You.
Site Admin
Posts: 5819
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: return double array

Post by ted »

In hoc a function returns a double precision value, not an array of double precision values. One can pass a double by reference, e.g.

Code: Select all

double bla[3]
for i=0,2 bla[i]=i
for i=0,2 print bla[i]
proc foo() { $&1[1]=PI }
for i=0,2 print bla[i]
but that's almost deprecated.

Much better is to use Vectors.

Code: Select all

objref cvec
cvec = new Vector(2)
proc setvec() { local i
  for i=0, $o1.size()-1 $o1.x[i] = sqrt(1+i)
It would be good to review the elements of hoc syntax, which are detailed in chapters 12 and 13 of The NEURON Book and documented at various places in the Programmer's Reference e.g. ... tml#syntax ... rogramming ... n/obj.html
Post Reply