How can I loop through a csv file that holds annual precipitation data and find out how many dry events there are?

1 view (last 30 days)
I have a csv file with 365 days of precipitation data. I am interested in finding out the average time between rainy days. For example, here's an shortened example of the matrix: [0 0 .3 0 0 .5 .6 0 0 0] I want to count the the first occurrences of zeroes in the matrix. So this matrix would give me an answer of 3. Any help would be appreciated.

Accepted Answer

dpb
dpb on 18 Nov 2013
Edited: dpb on 19 Nov 2013
I presume you mean the first nonzero occurrences...
mean(diff([0 find(r)])) % average between rainy days including first from the file
If don't want to count the first, drop the prepended '0'
APPENDUM:
BTW, finding the transitions isn't actually "average between rainy days" it's between rain "events" as it doesn't include anything for successive days of rain. One can do that by converting to logical and then diff()
isr=r>0; % logical "is rainy"
sum(diff([true isr])==-1)

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!