Dealing with NaNs in NetLogo

Dear all,

I came upon a problem regarding the interaction with NaN values and wondered if anyone worked around this.

In our NetLogo model we are using a habitat map which comprises grid cells colored according to the habitat suitability. The patches read the grid cells from the imported map and adopt the color value for their state variable “habitat” (0-1, steps of 0.1). There is however a number of grid cells outside the borders of the map (like a belt around the map) but still within the borders of the NetLogo world which do not have a color value but are labeled NaN (NAFlag -9999). The patches of these grid cells adopt NaN in their state variable “habitat”.

I am searching for a way to directly adress these NaNs, either through a turtle or through patches. My problem is, that I can not ask the patches or turtles to check if a habitat value is NaN. I tried using commands like:

if habitat of patch-here = NaN […

if habitat of patch-here = -9999 […

if habitat of patch-here < 0 or habitat of patch-here > 1 [

set patch-status “border” ]

Unfortunately none of these seem to be able to read or detect the presence of NaNs. Maybe I am just thinking in the wrong way and the solution is obvious. I would be very glad if someone could help me with this.

Thanks in advance!

Marcel

Update: I solved this problem by asking patches with habitat values >= 0 to set their status variable to “inside” (catching every patch that has a value). Then I asked patches with status variable != “inside” to set their status to “border”.

1 Like

Seems like a fine solution to me!

Small note: standard NetLogo style would be to use inside? rather than inside to indicate that it is a boolean.

1 Like