sum(rain(2:end) > 10 & rain(2:end) < 20 & rain(1:end-1) = 0)
rain(1:end-1)
: Get all the rain data bar the last element
rain(2:end)
: Get all the rain data bar the first element. The reason for this is to shift the data one element forward so that it's easy to search for a previous value of zero. (i.e. previous values are now in the same position as the values you want to check the limits for)
rain > 10
will return a logical vector with 1
s where it is greater than 10 and 0
s otherwise. Calling sum
on this just adds up all the 1
s so it proxies for counting them.