How to find the maximum number of Consecutive dry days over time period?

18 views (last 30 days)
I have daily precipitation data in a netcdf format. I have to calculate Consecutive dry days for a June,July,August,September(JJAS) monsoon. I have an array it is having 122 values with single coloum. I have to find out what is the maximum number of consecuitive dry days and also which month?
Can any one help me to clear this?
Thank you.

Answers (2)

David Sanchez
David Sanchez on 25 Mar 2015
I way of doing what you need with no need of toolboxes or special functions is this. Obviously, it would be much easier if you use some built-in matlab functions, but it works this way too:
monsoon_array = randi([0 1],122,1); % 122x1 array with 0s and 1s randomly distributed. I did this to have data to work with
max_dry = 0; % initialize the maximum number of consecuitive dry days
counter = 0;
for k=1:122
if monsoon_array(k) == 0
counter = counter + 1;
if counter > max_dry
max_dry = counter;
max_dry_position = k - counter;
counter = 0;
-> max_dry will return the maximum number of consecuitive dry days
-> max_dry_position will return the initial position (day) of the consecutive dry days
Image Analyst
Image Analyst on 25 Mar 2015
You didn't answer my questions, so it's still unclear. But I'll answer your question above:
dry = data < 1;
Better information will yield better answers from us.

Sign in to comment.

Image Analyst
Image Analyst on 24 Mar 2015
Exactly what do you have, and what do you need? Do you have an N row by 2 column array where column1 is the date and column2 is the precipitation? Do you already have a way to get your data in from the cdf file? What does "calculate consequitive dry days" mean? Do you want an array of the number of days in each dry spell? Do you want the dates of those days also? Can you supply a cdf file with code to read it in? Or can you supply an numerical example? Can you read this and fix your question? Right now there are too many things for us to guess on so we'd have to put in too much work to cover all possibilities, or else make some assumptions and end up not doing what you need. Also, do you have the Image Processing Toolbox because the regionprops() function in there would make this really easy?

Community Treasure Hunt

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

Start Hunting!

Translated by