Lu Yang
Lu Yang

Reputation: 11

netlogo export to csv

I'm new to NetLogo so probably it's a dumb question. while I'm trying to export turtles, patches, global variables to separated CSV files, this one works:

csv:to-file "turtles.csv" [ (list xcor ycor color shape) ] of turtles

but the following two don't:

csv:to-file "patches.csv" [ (list xcor ycor cluster-number) ] of patches error: this code can't be run by a patch, only a turtle

csv:to-file "statistics.csv" (list meet meet-agg meetown meetown-agg meetother meetother-agg coopown coopown-agg coopother coopother-agg defown defown-agg defother defother-agg) error: Extension exception: Expected a list of lists, but 1016 was one of the elements.

could someone help me with it? Thanks in advance!

Upvotes: 1

Views: 1877

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

About:

csv:to-file "patches.csv" [ (list xcor ycor cluster-number) ] of patches

I'm guessing the only problem is that you're trying to use xcor and ycor, which are turtle variables, instead of pxcor and pycor, which are patches variables. You need:

csv:to-file "patches.csv" [ (list pxcor pycor cluster-number) ] of patches

As for this one:

csv:to-file "statistics.csv" (list meet meet-agg meetown meetown-agg meetother meetother-agg coopown coopown-agg coopother coopother-agg defown defown-agg defother defother-agg)

one thing to keep in mind is that csv:to-file expects a "list of lists", and your code produces a single list, which is likely the problem. If all those variables are global variables, and you just want them in a single row in your CSV file, you could just wrap your list in another list:

csv:to-file "statistics.csv" (list (list meet meet-agg meetown meetown-agg meetother meetother-agg coopown coopown-agg coopother coopother-agg defown defown-agg defother defother-agg))

But it's hard to diagnose your problem precisely without more information. Can you tell us what makes you think it's not working? What are you trying to do?

Upvotes: 3

Related Questions