使用 round 命令时出错以及如何在 NetLogo 6.2 中导出 .csv table
Error using round command and how to export a .csv table in NetLogo 6.2
从昨天开始我一直在尝试编写以下代码:
to output
file-open ( word NameOutfile-output ".csv" )
ifelse Integer? = true ; interger switch in GUI
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " round my-xcor " ; " round my-yco )]
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " my-xcor " ; " my-ycor )]
file-close
end
- 我有非整数坐标值。我想在界面上放一个开关,如果打开它,它将生成一个带有整数值的输出。但是,它给出了以下错误:ROUND 期望输入是一个数字,但得到的是列表 [1 2 1 1 1]。
- 我不知道如何关闭创建的 .csv 文件。例如:我导出一个 .csv table。如果我再次 运行 它,模型会将结果保存在已经创建的 table 中。我希望那没有发生。有可能吗?
- 正如您所说,NetLogo 告诉您
round
想要一个数字作为输入,但您给它的是一个列表。
您可以通过以下方式解决此问题 map, which lets you run reporters on all elements of a list (and round 确实是一名记者):
to round-my-list
let my-list [3.1 5.6 8.32]
let my-list-rounded (map round my-list)
print my-list-rounded
end
- 您遇到的文件是标准行为。从位于
file-open
的 NetLogo 词典中,您可以 read this:
When opening a file in writing mode, all new data will be appended to the end of the original file. [...] If you don't want to append, but want to replace the file's existing contents, use file-delete to delete it first, perhaps inside a carefully if you're not sure whether it already exists.
所以如果你每次都想要一个新文件,你应该在你的代码中添加一些东西,首先告诉你删除那个文件;然后,再写一遍。按照 NetLogo 词典中的建议组合使用 file-delete
和 carefully
:
to output
carefully
[file-delete ( word NameOutfile-output ".csv" )]
[]
file-open ( word NameOutfile-output ".csv" )
ifelse Integer? = true ; interger switch in GUI
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " round my-xcor " ; " round my-yco )]
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " my-xcor " ; " my-ycor )]
file-close
end
从昨天开始我一直在尝试编写以下代码:
to output
file-open ( word NameOutfile-output ".csv" )
ifelse Integer? = true ; interger switch in GUI
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " round my-xcor " ; " round my-yco )]
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " my-xcor " ; " my-ycor )]
file-close
end
- 我有非整数坐标值。我想在界面上放一个开关,如果打开它,它将生成一个带有整数值的输出。但是,它给出了以下错误:ROUND 期望输入是一个数字,但得到的是列表 [1 2 1 1 1]。
- 我不知道如何关闭创建的 .csv 文件。例如:我导出一个 .csv table。如果我再次 运行 它,模型会将结果保存在已经创建的 table 中。我希望那没有发生。有可能吗?
- 正如您所说,NetLogo 告诉您
round
想要一个数字作为输入,但您给它的是一个列表。
您可以通过以下方式解决此问题 map, which lets you run reporters on all elements of a list (and round 确实是一名记者):
to round-my-list
let my-list [3.1 5.6 8.32]
let my-list-rounded (map round my-list)
print my-list-rounded
end
- 您遇到的文件是标准行为。从位于
file-open
的 NetLogo 词典中,您可以 read this:
When opening a file in writing mode, all new data will be appended to the end of the original file. [...] If you don't want to append, but want to replace the file's existing contents, use file-delete to delete it first, perhaps inside a carefully if you're not sure whether it already exists.
所以如果你每次都想要一个新文件,你应该在你的代码中添加一些东西,首先告诉你删除那个文件;然后,再写一遍。按照 NetLogo 词典中的建议组合使用 file-delete
和 carefully
:
to output
carefully
[file-delete ( word NameOutfile-output ".csv" )]
[]
file-open ( word NameOutfile-output ".csv" )
ifelse Integer? = true ; interger switch in GUI
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " round my-xcor " ; " round my-yco )]
[file-print ( word "id;my_xcor;my_ycor" ) file-print ( word self " ; " my-xcor " ; " my-ycor )]
file-close
end