NetLogo-在一定范围内绘制所有乌龟的总和

时间:2019-02-11 13:38:39

标签: netlogo

我想绘制所有拥有2到4个值的海龟的总和。如何实现?

我只用plot count turtles with [value = 4]得到的海龟总数为4,但是,我需要类似plot count turtles with [2 <= value => 4]的东西。

我该如何实现?

我的MWE是:

breed [ turtles ]
turtles-own [ value ]

to setup
  clear-all
  create-turtles 100
  [
    set value random 4
  ]
  reset-ticks
end

to go
  ask turtles [
    rt random 360
    fd 1
  ]
  tick
end

1 个答案:

答案 0 :(得分:3)

NetLogo不支持2 <= value => 4语法。您需要分别编写两个条件:

plot count turtles with [ value >= 2 and value <= 4 ]

顺便说一句,如果您想绘制值的 sum 而不是具有该间隔值的海龟的 count ,可以这样写:

plot sum [ value ] of turtles with [ value >= 2 and value <= 4 ]