【问题标题】:How to plot a cumulative sum (running total) of a turtles-own variable in Netlogo?如何在 Netlogo 中绘制海龟自己的变量的累积总和(运行总和)?
【发布时间】:2022-01-01 05:39:39
【问题描述】:

我可以使用下面的代码绘制每只动物的蠕虫总数(在 图 1 中可视化)。

plot sum [worm-number] of animals

图 1。

我希望我的图表像 图 2 那样是累积的,但我不知道如何编码。 Previous examples 使用在 NetLogo 6.2.0 中不起作用的旧语法,并且不显示如何绘制数据。

图 2。

【问题讨论】:

    标签: simulation netlogo agent-based-modeling


    【解决方案1】:

    您只需要使用一个全局变量来跟踪新蠕虫,并参考该变量进行绘图。

    由于我们没有您的代码的完整示例,因此我将编写一些似是而非地模仿您应该做的事情:

    breed [animals animal]
    
    globals [
     cumulative-worms
    ]
    
    ; **************************
    ; The rest of your code here
    ; **************************
    
    to get-infected   ; The procedure executed by animals when they get new worms.
     let new-worms (1 + random 5)
     set worm-number (worm-number + new-worms)
     set cumulative-worms (cumulative-worms + new-worms)
    end
    

    此时您可以创建一个将使用plot cumulative-worms 的绘图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 2015-11-27
      • 2017-09-16
      • 2020-03-04
      • 1970-01-01
      • 2021-01-18
      相关资源
      最近更新 更多