Suppose that
all cells have been created
each cell is an instance of a class
each cell class has a public member called soma
each cell instance has been appended to a List called cells
you want to plot soma.v(0.5) for the first NUMTOPLOT cells in the List called cells
You could use the GUI to create a Voltage axis graph, then delete the "v(.5)" from that graph, and then manually do this:
Code: Select all
for i = 0,NUMTOPLOT-1
use Plot what? to add cells.o(i).soma.v(0.5)
(in fact you should probably do this once for two or three cells, just to make sure that you know the names of the variables you want to plot).
Or you could do it algorithmically.
First design the algorithm. You'll want a procedure that
1. spawns a Graph
2. adds the desired variables to the Graph's plot list
3. then adds the graph to graphList[0] so it will be automatically updated on each fadvance(), and that updating will plot the value of each variable in its plotlist vs. t at the end of fadvance().
This is easy.
Code: Select all
objref g
proc spawng() {
g = new Graph()
addtog($1, g) // $1 tells how many variables to add to g's plotlist
addplot(g,0) // make sure g updates automatically on each fadvance()
}
addplot() is part of NEURON's standard run system. addplot(g, 0) tells it to add g to graphList[0]. Suggest you look in NEURON's hoc library and examine proc addplot() in stdrun.hoc
Now we need to invent proc addtog(). This is only a bit more difficult than inventing spawng.
Code: Select all
proc addtog() {
if ($1>cells.count()) { // prevent errors
print "doit() argument ", $1, "is too big"
} else {
for ii=0,$1-1 {
makevarname(ii) // build a string that is the name of the variable to be plotted
$o2.addvar(varname) // add the variable called "varname" to $o2's plotlist
}
}
}
Finally we need makevarname.
Code: Select all
strdef varname
proc makevarname() {
sprint(varname, "cells.o(%d).soma.v(0.5)", $1)
// to see the name of each plotted variable, uncomment the next line
// print varname
}
The whole thing is
Code: Select all
strdef varname
proc makevarname() {
sprint(varname, "cells.o(%d).soma.v(0.5)", $1)
// print varname
}
proc addtog() {
if ($1>cells.count()) {
print "doit() argument ", $1, "is too big"
} else {
for ii=0,$1-1 {
makevarname(ii)
$o2.addvar(varname)
}
}
}
objref g
proc spawng() {
g = new Graph()
addtog($1, g)
addplot(g,0) // update g automatically on each fadvance()
}
Put this in a hoc file by itself. In your main program, after model setup is complete but before the run() statement is called, execute
load_file("name of the file") // substitute with the name of the hoc file that contains the above code
and then execute
spawng(NUMTOPLOT)
where NUMTOPLOT is the number of cells whose soma.v(0.5) you want to add to the graph.