Search code examples
global-variablescellnetlogo

Count number of different values of a variable in NetLogo


I am building a simulation of the epidermal cells in NetLogo. I have two type of cells, progenitors and post mitotic cells. The progenitors are the cells which can divide into either progenitor or post mitotic. Each run begins with a number of 239 progenitor cells with each their own identity (from 1 to 239) which is a turtles-own. Each time a progenitor divides, the identity is given to the offspring.

I want to count the number of different identities after a certain amount of ticks. I tried it with a monitor and with a list but it did not work.

Here is a small part of the code I have made:

turtles-own [ identity]
globals [ id-count]

to setup
ask patches [sprout-postmitotic 1]

ask n-of (( 22 / 100) * count postmitotic) patches [ 

ask postmitotic-here [
hatch-progenitor 1
[
    set identity id-count
  set id-count id-count + 1 ]
   die ] 
]
end


to go
ask progenitor[
if random-float 1 < l [
      hatch-postmitotic 1
    ]
end

Solution

  • If you post code for a question like this, try to produce a minimal example to support the question. Here are two approaches. (The first illustrates the use of table:counts, which gives access to more information.)

    extensions [table]
    turtles-own [identity]
    to setup
      ca
      crt 1000 [set identity random 1000]
    end
    to-report id-count-01
      let _idcts table:counts [identity] of turtles
      let _unique table:keys _idcts
      report length _unique
    end
    
    to-report id-count-02
      let _unique remove-duplicates [identity] of turtles
      report length _unique
    end