This is not the most efficient way, neither the clearest, but it's compact. In a language like Matlab it would be the preferred approach.
sum((outputarray[1:end-1] .< 0) & (outputarray[2:end] .>= 0)) Den onsdagen den 30:e juli 2014 kl. 22:03:32 UTC+2 skrev yaois...@gmail.com: > > Hi guys, > > I asked this in a previous thread, but because that diverged off-topic > from my existing question, I decided to create a new thread. > > Anyhow, say I have an array > > outputarray = > Float64[-1.23423,-3.23423,-2.34234,-2.12342,1.23234,2.23423,-2.23432,5.2341,0.01111,1.23423] > > This array lists the output of some function. I want to count the number > of times that the function passes by or equals 0 while emerging from a > negative f(x). > > In pseudocode, I want to do: > > function counter(outputarray) > count = 0 > for i in Int64[1:len(outputarray)] > if outputarray[i] >= 0 && outputarray[i-1] < 0 > count += 1 > end > end > return count > end > > What would be the most efficient way of doing this in Julia? > > Thanks, > Wally >