use matrixes in Neuron

Moderator: wwlytton

Post Reply
nasrin.sh
Posts: 18
Joined: Mon Sep 20, 2010 10:28 pm
Location: Iran

use matrixes in Neuron

Post by nasrin.sh »

Dear Admin,
i m trying to use a matrix in neuron to save some data which is exported from Matlab to Neuron,which is the weight between neuron cells and i stored them in a file is named "f3" and then read it by scanvar() function

Code: Select all

objectvar f3
f3.ropen("MyDataw.dat")
....
proc connectcells() {local i , j , k localobj src, target, syn, nc
objref m
m = new Matrix(3,3)
nclist = new List()
  for i=0, cells.count-1 {       
     // iterating over sources
    for j=0, m.nrow-1 {
      for k=0,m.ncol-1 {
        m.x[j][k] = f3.scanvar()
          if(m.x[j][k]==m.x[k][j] && m.x[j][k]>0){
             src = cells.object(j)
             target = cells.object(k)
             syn = target.synlist.object(0)
                                           // the first object in synlist
                                            // is an ExpSyn with e = 0, therefore an excitatory synapse
             nc = src.connect2target(syn)
             nclist.append(nc)
             nc.delay = 1
             nc.weight = 0.01
            }
          else{
         print "Run the program again n Enter a symmetrical Matrix for weights"
         }
      }
    }
  }
}

bt when i run this code i face an Error as this:
syntax error near line 133
m = new Matrix(3,3)
^
would u please help me to correct the error?
ted
Site Admin
Posts: 6303
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: use matrixes in Neuron

Post by ted »

The error is caused by a mismatch between the left hand and right hand sides of the assignment statement
m = new Matrix(3,3)
There is a mismatch because hoc does not regard m as being an objref.

"But I declared
objref m
right before the assignment statement!"

Yes, but that declaration was done inside of a proc, and I bet you never declared
objref m
outside of any proc or func. Before a variable name can be used as an objref, it must be declared to be an objref, and that declaration must occur _outside_ of any proc or func. If the only declaration
objref m
is inside your proc, hoc will ignore the declaration and treat m as an ordinary floating point variable. The way to fix your code is to insert an
objref m
statement into your code, _outside_ of any proc or func, and _before_ your proc is defined. So just change
proc connectcells() {
. . . etc. . . .
}
to
objref m
proc connectcells() {
. . . etc. . . .
}
and the error message will go away.

The same rule applies to variable names you might want to use as strdefs or doubles. I'm sure I read about this somewhere or other in the Programmer's Reference, but right now I can't seem to find it.
Post Reply