qertsoc.blogg.se

Netlogo lput
Netlogo lput





netlogo lput
  1. #Netlogo lput code#
  2. #Netlogo lput series#
  3. #Netlogo lput free#

in 'list-of-numbers' by the 'convert-user-string' procedure) and the following space in the string. By using 'but-first' repeatedly, this procedure gets rid of the first number (which has already been stored Simply reporting the position of the next space in the string. Ifelse (position-of-next-space str = FALSE) Therefore, this procedure is needed in order to get either TRUE or FALSE to be used in the the position of the character in the given string) or 'FALSE' (in case the item is not present in the the 'position' command (used by the 'position-of-next-space' procedure) reports either a number (i.e. This reporter is needed as a condition for the while loop in 'convert-user-string'. To-report more-than-one-number-in-string? Let next-number-as-string (substring temp-string 0 position-of-next-space temp-string) Set list-of-numbers (list) Initiating this variable as a list in order to be able to use 'lput'.

#Netlogo lput code#

At that point, the last line of code adds what is left of the string (i.e. the 'more-than-one-number-in-string? temp-string'condition evaluates as 'FALSE' and the while loop When there is only one number left in the string (identified by the absence of spaces in the string), string up to the next non-space character.

netlogo lput

value to 'list-of-numbers' by using 'read-from-string' and 'lput'. space), the while loop extracts the first number with 'substring' and then assigns it as a numeric As long as there are at least two numbers in the string (identified by the presence of at least one user input intact - hence we use this 'temp-string' to trim the string without worries. missing something here) but also because you might want to keep the value of the

#Netlogo lput free#

'user-string' directly (I am not sure why, anyone please feel free to say if I'm the 'trim-string-to-next-nonspace' procedure won't let me change the value of Temp-string A temporary variable being the alter-ego of 'user-list'. List-of-numbers The list where values from the input string will be stored. The procedure I posted above is the condensed version of the initial code I made, that I am leaving here below abundantly commented: globals [ Observer> show convert-user-string user-string So for example: observer> set user-string "0.5 0.2 0 0.2 0.5" Set list-of-numbers lput (read-from-string temp-string) (list-of-numbers) Set list-of-numbers lput (read-from-string next-number-as-string) (list-of-numbers) Let next-number-as-string (substring temp-string 0 position " " temp-string) The procedure below is a reporter procedure that executes this workflow and reports a list of values as read from the string (it only needs a user-string input box in the Interface): to-report convert-user-string the whole remaining string) to list-of-numbers outside the loop, and it's all done. When the loop condition evaluates as FALSE it means that only one number is left in the string.Drop the first number in the string (using position " " string, repeat and but-first) and start the loop again.Read that substring as a numeric value (with read-from-string) and add it to list-of-numbers (with fput).Extract a substring that goes from the first character to the first space excluded (done with substring).Create a loop that goes on as long as the string contains more than one number (= as long as it contains at least one space, checked using position " " string).You can do it with a combination of position, substring, read-from-string and fput. I am very new to NetLogo, so sorry if my question is silly or I have not made something clear! I also attempted to use the explode function from the string extension ( ), but my version of Netlogo (6.2.0) did not like the API from that extension and wouldn't allow me to use it.

#Netlogo lput series#

I have tried using read-from-string, but it also doesn't like a series of numbers entered like above. not reading in a text file of values) to make it easier to change, as it is something that I suspect will get played around with a lot. " ")? I am open to alternatives too, although I would prefer to keep it in Netlogo (e.g. So, how can I parse the string the basis of a space (i.e. If I set the type to numeric, it will only allow a single number to be entered. Unfortunately, having an input set up like above will spit out "0.5 0.2 0 0.2 0.5" if I set the type to be a string.

netlogo lput

, so I can then use the numbers that they enter for some calculations. What I would like to have from the input shown above is a list of five numbers, e.g. For my model I would like to have an input where the user can enter a series of values.







Netlogo lput