How to save data in different column in csv format for each 5 ticks.
I want to export the x-cor, y-cor and heading angle data of the agents to CSV
file for every 5 ticks. I tried to use the example given in the NetLogo
library but it only exports the first tick data and stops(only one column).
Anyone could share me your idea or code if you already have done it.
In setup, you want to open your output file and write your column headings:
file-print csv:to-row (list "id" "xcor" "ycor" "heading")
Note I’m adding turtle ids to the output to make it easier to track which
row corresponds to which turtle.
Then, add procedure to do the output the data:
ask turtles [
file-print csv:to-row (list who xcor ycor heading)
file-flush ; Make sure that the output is saved to file
Call this procedure from go
If you want to make it only output every 5 ticks, do if ticks mod 5 = 0 [
output-turtle-data ] instead!
You can also do this without the csv extension, but it’s a little messier
as you have to manage columns yourself. The header output in setup
"id,xcor,ycor,heading" and the print statement in output-turtle-data
becomes: file-print (word who "," xcor "," ycor "," heading)