是否可以导入不同的文件?
Is it possible to import different files?
首先,如果这是一个愚蠢的问题,我很抱歉,因为我是 Netlogo 的新手。
我已经完成了 Steven Railsback 和 Volker Grimm 书中的蝴蝶模型,并且有一个练习可以导入一个文件,该文件具有坐标 X Y 和一个在该示例中为高程的变量。到目前为止,好的。但我目前正在尝试实现一个模型,其中我们有 4 个不同的文件,每个文件包含相同的坐标但不同的变量,我的问题是:是否可以导入这 4 个文件并在我们的 [=14= 中有 4 个不同的变量]?
只是为了确保 - 您正在使用找到的 "ElevationData.txt" 文件 here, correct? So your file reading code should look more or less exactly as shown in the Railsback and Grimm 书:
file-open "ElevationData.txt"
while [not file-at-end?] [
let next-X file-read
let next-Y file-read
let next-elevation file-read
ask patch next-X next-Y [set elevation next-elevation]
]
file-close
因此,如果您要导入的其他文件大部分与 "ElevationData.txt" 文件相同,但第三列中的值不同,您绝对可以相应地修改该代码块。如果我们以植被覆盖为例,您需要一个 patches-own
变量, 以及 已经存在的 elevation
变量:
patches-own [ elevation veg-cover ]
现在假设您有一个 "VegetationData.txt" 文件,看起来像:
0 0 0.86
1 0 0.15
2 0 0.42
3 0 0.44
4 0 0.43
5 0 0.33
...
在你有运行你的高程导入之后,你可以做完全相同的事情但是植被:
file-open "VegetationData.txt"
while [not file-at-end?] [
let next-X file-read
let next-Y file-read
let next-veg-cover file-read
ask patch next-X next-Y [set veg-cover next-veg-cover]
]
file-close
现在您的补丁将有一个值分配给它们的 elevation
和 veg-cover
变量。
也就是说,如果可能的话,最好合并您的输入文件并将它们一起加载。如果您有一个组合的高程和植被文本文件,如下所示:
0 0 532.4 0.86
1 0 529.3 0.15
2 0 526 0.42
3 0 520 0.44
4 0 519.5 0.43
5 0 519.3 0.33
...
在组合数据集 ("ComboData.txt") 中,您仍然有 x 和 y 列,但现在第三列是高程,第四列是植被覆盖。现在您可以通过稍微修改导入代码来同时加载所有内容:
file-open "ComboData.txt"
while [not file-at-end?] [
let next-X file-read
let next-Y file-read
let next-elev file-read
let next-veg-cover file-read
ask patch next-X next-Y [
set elevation next-elev
set veg-cover next-veg-cover
]
]
file-close
首先,如果这是一个愚蠢的问题,我很抱歉,因为我是 Netlogo 的新手。
我已经完成了 Steven Railsback 和 Volker Grimm 书中的蝴蝶模型,并且有一个练习可以导入一个文件,该文件具有坐标 X Y 和一个在该示例中为高程的变量。到目前为止,好的。但我目前正在尝试实现一个模型,其中我们有 4 个不同的文件,每个文件包含相同的坐标但不同的变量,我的问题是:是否可以导入这 4 个文件并在我们的 [=14= 中有 4 个不同的变量]?
只是为了确保 - 您正在使用找到的 "ElevationData.txt" 文件 here, correct? So your file reading code should look more or less exactly as shown in the Railsback and Grimm 书:
file-open "ElevationData.txt"
while [not file-at-end?] [
let next-X file-read
let next-Y file-read
let next-elevation file-read
ask patch next-X next-Y [set elevation next-elevation]
]
file-close
因此,如果您要导入的其他文件大部分与 "ElevationData.txt" 文件相同,但第三列中的值不同,您绝对可以相应地修改该代码块。如果我们以植被覆盖为例,您需要一个 patches-own
变量, 以及 已经存在的 elevation
变量:
patches-own [ elevation veg-cover ]
现在假设您有一个 "VegetationData.txt" 文件,看起来像:
0 0 0.86
1 0 0.15
2 0 0.42
3 0 0.44
4 0 0.43
5 0 0.33
...
在你有运行你的高程导入之后,你可以做完全相同的事情但是植被:
file-open "VegetationData.txt"
while [not file-at-end?] [
let next-X file-read
let next-Y file-read
let next-veg-cover file-read
ask patch next-X next-Y [set veg-cover next-veg-cover]
]
file-close
现在您的补丁将有一个值分配给它们的 elevation
和 veg-cover
变量。
也就是说,如果可能的话,最好合并您的输入文件并将它们一起加载。如果您有一个组合的高程和植被文本文件,如下所示:
0 0 532.4 0.86
1 0 529.3 0.15
2 0 526 0.42
3 0 520 0.44
4 0 519.5 0.43
5 0 519.3 0.33
...
在组合数据集 ("ComboData.txt") 中,您仍然有 x 和 y 列,但现在第三列是高程,第四列是植被覆盖。现在您可以通过稍微修改导入代码来同时加载所有内容:
file-open "ComboData.txt"
while [not file-at-end?] [
let next-X file-read
let next-Y file-read
let next-elev file-read
let next-veg-cover file-read
ask patch next-X next-Y [
set elevation next-elev
set veg-cover next-veg-cover
]
]
file-close