Skip to content
Prev 367129 / 398506 Next

Wrap to 360

The key function is '%%' (remainder), but its result needs to be
tweaked at mulitplies of 360 because Matlab's definition of wrapTo360
is

lonWrapped = wrapTo360(lon) wraps angles in lon, in degrees, to the
interval [0 360] such that 0 maps to 0 and 360 maps to 360. (In
general, positive multiples of 360 map to 360 and negative multiples
of 360 map to zero.)

wrapTo360 <- function (lon)
{
    ret <- lon%%360
    ret[lon >= 360 & ret == 0] <- 360
    ret
}

As in:
[1] 359   0   1 359   0   1 359   0   1 359 360   1 360   1


Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Feb 13, 2017 at 8:44 AM, Peter Mills <peter.mills at strath.ac.uk> wrote: