-->

NetLogo: Is there a way to customize CSV files gen

2020-03-26 07:52发布

问题:

This might seems really basic , but using export plot feature of NetLogo what I get is something like this:

x,y,color,pen down?,x,y,color,pen down?,x,y,color,pen down?,x,y,color,pen down?

Is there a way to not to include color and pen down and Just one X using netlogo itself?

  x,y,y,y,y

I can filter unwanted data in R or excel but I have many plots and having clutter free data files make my work much easier :)

回答1:

In a word, no.

Someone could write an extension that provides this.



回答2:

Actually, there is a workaround using the built-in csv extension (see https://ccl.northwestern.edu/netlogo/docs/csv.html). All you have to do is to build an array to programmatically gather the same information displayed in the plots and that can be written to a csv file later on as follows (I usually use a button for this purpose):

extensions [array csv]

to write-csv
  let csv-delimiter ";"
  let output [[ "x" "val1" "val2" ]]
  set output lput [ 1 2 3 ] output
  set output lput [ 4 5 6 ] output
  (csv:to-file "c:/temp/filename.csv" output csv-delimiter)
end  

This will result in the following csv file:

x;val1;val2
1;2;3
4;5;6

To write your model outputs to a file, you could construct the array output in your setup procedure and add each line of data in your go procedure (with your model time unit being the value for x).

Please be aware that I changed the csv delimiter to ';' instead of ',' in my example in order to be able to open the file in a German-language version of Microsoft Excel.



标签: netlogo