在NetLogo中,如何每隔N个刻度提取海龟子集的x和y坐标?
我有一个非常简单的模型,50只海龟离开一个中心点。我希望能够在行为空间中每隔N个刻度提取一个子集的空间坐标在NetLogo中,如何每隔N个刻度提取海龟子集的x和y坐标?,netlogo,Netlogo,我有一个非常简单的模型,50只海龟离开一个中心点。我希望能够在行为空间中每隔N个刻度提取一个子集的空间坐标(xcor,ycor)。希望你能帮忙 模运算符mod可能是实现这一点的最简单方法。它从除法运算中输出余数,因此您只需使用一个逻辑标志,以便仅当ticks除以n等于0时,才提取坐标。例如: to setup ca crt 10 reset-ticks end to go ; set up lists for example output let tlist [] le
(xcor,ycor)
。希望你能帮忙 模运算符mod
可能是实现这一点的最简单方法。它从除法运算中输出余数,因此您只需使用一个逻辑标志,以便仅当ticks
除以n等于0时,才提取坐标。例如:
to setup
ca
crt 10
reset-ticks
end
to go
; set up lists for example output
let tlist []
let xlist []
let ylist []
ask turtles [
rt random 60 - 30
fd 1
]
tick
; If ticks is not zero, and the remainder of
; the number of ticks / 3 is zero, extract
; some info about the turtles and print it.
if ticks > 0 and ticks mod 3 = 0 [
ask turtles with [ xcor > 0 ] [
set tlist lput self tlist
set xlist lput xcor xlist
set ylist lput ycor ylist
]
print tlist
print xlist
print ylist
]
end
运行几次,您将看到在
勾选3(以及6、9、12等)时,列表被打印出来。请注意,tick
增量的位置将影响实际提取此输出的时间-在上面的示例中,tick
发生在go过程结束时,但在计算if
语句之前。模运算符mod
可能是最简单的方法。它从除法运算中输出余数,因此您只需使用一个逻辑标志,以便仅当ticks
除以n等于0时,才提取坐标。例如:
to setup
ca
crt 10
reset-ticks
end
to go
; set up lists for example output
let tlist []
let xlist []
let ylist []
ask turtles [
rt random 60 - 30
fd 1
]
tick
; If ticks is not zero, and the remainder of
; the number of ticks / 3 is zero, extract
; some info about the turtles and print it.
if ticks > 0 and ticks mod 3 = 0 [
ask turtles with [ xcor > 0 ] [
set tlist lput self tlist
set xlist lput xcor xlist
set ylist lput ycor ylist
]
print tlist
print xlist
print ylist
]
end
运行几次,您将看到在勾选3(以及6、9、12等)时,列表被打印出来。请注意,tick
增量的位置将影响实际提取此输出的时间-在上面的示例中,tick
发生在go过程结束时,但在计算if
语句之前