Search code examples
listhistogramnetlogo

I need the age of my agents before they die to create a list and histogram


Sorry but I am new to Netlogo, here is my problem:

I have created polar bears, who have better chances to survive on ice than on dirt. I am wondering which effect the ice dirt ratio has on the lifespan of the polar bears. For that I need a list of the polar bears age before they die and create a histogramm with it.

I am greatful for any help.

I got told to use the comand lput, but to be honest I dont quite know how that comand works.


Solution

  • lput is used to append a value to a list. It reports a new list with the value appended at the end of the list. So every time before one of your polar bears dies (die), you want to add the age of that bear to a list and store this new list using set.

    What you need to do

    1. initialize a list during simulation setup, e.g. set age-death-list []
    2. add the age of bears to the list when they die, e.g. set age-death-list lput age age-death-list
    3. plot this list as a histogram in the GUI, e.g. histogram age-death-list

    Here you find examples and syntax on how to use lput and histogram.