如何使用 NetLogo 中的输入从界面指定矩阵的元素?

How can I specify the elements of a matrix from the interface using input in NetLogo?

我在我的模型中使用矩阵扩展,我希望能够通过 GUI 更改此矩阵的元素,而不是对它们进行硬编码。目前看起来是这样的:

extensions [matrix]
globals [test_matrix]

to setup
   set test_matrix matrix:from-row-list [[
     1
     2
     3
     4
    ]]
end

但是如果我尝试在 GUI 上使用 Input 函数设置值,我会得到一个错误 'expected a literal value.'

 set test_matrix matrix:from-row-list [[
         element1
         element2
         element3
         element4
        ]]

当您在第一部分中执行 [ 1 2 3 4 ] 时,您正在创建一个列表文字,而 NetLogo 只允许列表文字中的常量值(数字、字符串、其他列表文字)。参见 the Lists section of the programming guide for more

要创建包含非文字(变量或表达式)值的列表,请使用 the list primitive

set test_matrix matrix:from-row-list (list (list 
  element1 
  element2 
  element3 
  element4
))

另见 the FAQ entry