adkane
adkane

Reputation: 1441

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

I'm using the matrix extension in my model and I'd like to be able to change the elements of this matrix through the GUI rather than hard coding them. It looks like this at the moment:

extensions [matrix]
globals [test_matrix]

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

But if I try to set the values using the Input function on the GUI I get an error that it 'expected a literal value.'

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

Upvotes: 0

Views: 109

Answers (1)

Jasper
Jasper

Reputation: 2790

When you do [ 1 2 3 4 ] in the first section you're creating a list literal, and NetLogo only allows constant values in list literals (numbers, strings, other list literals). See the Lists section of the programming guide for more.

To make a list with non-literal (variable or expression) values use the list primitive:

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

See the FAQ entry as well.

Upvotes: 2

Related Questions