multiple itertions of plots

Moderator: wwlytton

Post Reply
stu2010
Posts: 5
Joined: Mon Jun 30, 2014 9:28 am

multiple itertions of plots

Post by stu2010 »

Hello I am trying to run a loop of different plots
Using a for loop in my biophysics hoc file I am able to change a specific ion channel in steps of 0.1.

What I would like to do is to be able to call the biophysics hoc in each iteration and plot the corresponding waveforms on different plots

Some direction in this matter would be greatly appreciated
Thanks
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: multiple itertions of plots

Post by ted »

Start by writing an outline that expresses the whole task as a sequence of simpler tasks. Example:

Code: Select all

someparameter = startvalue
while (someparameter <= endvalue) {
  run a simulation
  plot results
  increase someparameter by someincrement
}
This assumes that you want each simulation's results to appear in a separate graph.

Note that "run a simulation" is simply run() if you are using NEURON's standard run system; if you aren't, why aren't you?
stu2010
Posts: 5
Joined: Mon Jun 30, 2014 9:28 am

Re: multiple itertions of plots

Post by stu2010 »

Hey Ted
I worked thanks

Only problem is all 10 plots are graphing the last iteration of the loop, any way I can get it to graph a plot for every iteration?

Thanks
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: multiple itertions of plots

Post by ted »

Yes, and you probably noticed that each time you add a new graph, the simulation takes longer to run. The problem is that each graph has the same list of variables that are to be plotted vs. t.

Instead of plotting somevar vs. t, you need to

Code: Select all

// after model setup but before your loop that runs a bunch of simulations
 . . . code that sets up Vector recording of somevar and t to a pair of Vectors somevarvec and tvec . . .
Then you can create a series of recordings of somevar and t, and plot each recorded pair in its own Graph. Here's how.

Code: Select all

// the ith element of each of these lists
// will correspond to the i+1'th run
objref somevarveclist, tveclist, glist
somevarveclist = new List()
tveclist = new List()
glist = new List()

someparameter = startvalue
while (someparameter <= endvalue) {
  run a simulation
  glist.append(newgraph(somevarvec, tvec))
  increase someparameter by someincrement
}
where newgraph() is

Code: Select all

obfunc newgraph() { localobj xtmp, ytmp, gtmp
  ytmp = $o1.c // make copies of the data to be plotted
  xtmp = $o2.c
  somevarveclist.append(ytemp) // save these copies
  tveclist.append(xtmp)
  gtmp = new Graph() // plot them
  ytmp.plot(gtmp,xtmp)
  gtmp.exec_menu("View = plot")
  return gtmp
}
If you want to make your program a bit nicer, change your while loop to a procedure like so

Code: Select all

objref paramvals
paramvals = new Vector()
proc batchrun() {
  paramvals = new Vector()
  somevarveclist = new List() // discard results of previous batch run
  tveclist = new List()
  glist = new List()

  someparameter = $1
  while (someparameter <= $2) {
    run a simulation
    glist.append(newgraph(somevarvec, tvec))
    paramvals.append(someparameter)
    increase someparameter by someincrement
  }
}
Then you can launch a batch run like so
batchrun(startvalue, endvalue)
Post Reply