NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo Models Library:
Code Examples/Extensions Examples/csv

(back to the library)

CSV Example

[screen shot]

Note: If you download the NetLogo application, every model in the Models Library is included.

WHAT IS IT?

This model shows how to use NetLogo's csv extension to load data from and write data to data to CSV files. This allows users to easily output data (e.g. value of turtle variables, result of calculations, etc.) to a standard CSV file.

THINGS TO NOTICE

The GENERATE-TURTLES button just creates 100 random turtles. The user can then use the WRITE-TURTLES-TO-CSV button to save the xcor, ycor, size, color and heading of each turtle into a CSV file called turtles.csv.

If you were interested in generating just one line of this CSV file at a time, you could use the csv:to-string primitive:

csv:to-string [ (list xcor ycor size color heading) ] of one-of turtles

The READ-TURTLES-FROM-CSV button does just the opposite: reads this data from turtles.csv and creates turtles with those properties.

Pressing ASK TURTLES [ DIE ] before READ-TURTLES-FROM-CSV will allow to remove the originally generated turtles and see that they are re-created with their original attributes.

(back to the NetLogo Models Library)