MATLAB: How to calculate the maximum consecutive dry days and wet days over time period
I have matrix (189×189) of daily precipitation in 20 years period (7300 files). I want to calculate the consecutive dry days and wet days in that period, where dry days is RR<1 and wet days is RR>1. can any one help me about this problem?
Best Answer
RR=randi([-255,255],189,189); % Prepare a random precipitation data %Assumption that RR is matrices of 189x189 and containing precipitation data if this assumption is correct then below mentioned steps will work dryDays=RR<1; noOfDryDays=find(dryDays); noOfWetDays=find(~dryDays);
Or Else First you need to import data in a variable then use above code snippets
Assuming your data are daily stock prices, you can use Y = diff(X,1,dim) to compute the difference across the n_th dimention of your data. If your data is a vector, you just need the 1st input.
Y will have 1 less data point than X since Y(1) is the result of X(2)-X(1).
Then look for positive values in Y. If Y(n) is positive that means the stock from X(n+1) increased from the previous day on X(n).
The output ofdatenum are whole days to the left of the decimal separator (as the number of days from January 0, 0000), and fractions of a day to the right. You can get other details about the days using the appropriatedatetime (link) functions.
Best Answer