I'm trying to obtain the surface of the different compartments.
I understood that to obtain it for a section I should write
Code: Select all
totalarea_soma = 0
soma for (x,0) totalarea_soma += area(x) # take into account the number of nseg
True.
soma for (x,0)
statement
is equivalent to the following pseudocode:
Code: Select all
for each segment in soma
do whatever statement says
In your particular case,
statement is a function that returns the value of the segment whose center is located at x.
Comment for readers who may be unfamiliar with iteration: this is an example of iteration. In particular, it is iterating over all the segments in soma in order to calculate the total surface area of soma. Translating from geekspeak to english, iteration is a process in which you start with a collection of things that we'll call S, and you do this:
Code: Select all
for each thing in S
do some task p
for the all neuron
Code: Select all
totalarea_neuron = 0
all for (x,0) totalarea_neuron += area(x) # take into account the number of nseg
Not quite. You meant this example to do the following
Code: Select all
for each section
for each segment in the current section
add the area of this segment to totalarea_neuron
But what will it actually do? See what happens if you execute the following example:
Code: Select all
create soma, dend
dend.nseg = 3
all for (x,0) print secname(), " ", x
If you're right, then this example should print
soma 0.5
dend 0.16666667
dend 0.5
dend 0.83333333
but it won't. Why? Because there's nothing that tells NEURON to iterate over all of the sections. You can fix this by changing "all" to "forall", because forall iterates over all sections that exist.
But is it possible l to obtain it for a subsets
Yes, as long as your code iterates over the sections that belong to a subset. In your third example, everything is OK until this statement
all_ABD for (x,0) totalarea_allABD += area(x)[/code]
which fails because there is nothing to tell NEURON to iterate over the sections that belong to the section list all_ABD. To fix this, change all_ABD to forsec all_ABD.
And be sure to read the Programmer's Reference entries on forall and forsec.