How to fill in a matrix and compute its binary frequency?

2 views (last 30 days)
Hello All,
I have thirty year of preciptation data in a vector form. I need to find the frequency of the dry and wet days and plot the frequency against days (1:365).
I am stuck as the following code place in the precipitation data however, i am not able to change it to a binary condition (Wet=1, dry=0). Can somebody help me out. I still have to count all the wet and dry days and make the frequency graph against the days (1:365).
Thanks
R=zeros(365,30); % Space for the data
P_data=P(:,4); % Preciptation data
n=length(P_data);
C=1;
for i=1:30;
for j=1:365;
R(j,i)=P_data(C);
C=C+1;
end
end
if R(j,i)>0;
R(j,i)=1; % imposing the wet conditon if the the value in the ith row and jth colum is larger then zero
else
R(j,i)=0;
end
  3 Comments
Image Analyst
Image Analyst on 25 Nov 2014
Yes, but you still didn't attach P, or give code to read it in.

Sign in to comment.

Answers (1)

dpb
dpb on 25 Nov 2014
Edited: dpb on 26 Nov 2014
Leap years not accounted for?
If not, as the above would indicate, then
R=reshape(P_Data,365,[])>0;
  2 Comments
Hydro
Hydro on 25 Nov 2014
yes, the leap year is ignored for this analysis. any thought about the code would be appreciated. I still don't see what i wanted to see (Probability of precipitation occurrence against duration in days (1:365).
dpb
dpb on 25 Nov 2014
Not quite sure what you mean, precisely by Probability of precipitation occurrence against duration in days (1:365) but R above will be a logical array of T for rainy days arranged by year in columns. So, P(R|day) =
Prainbyday=sum(R,2)/size(R,2);
Clearly P(noRain) is the complement. Is that not what you're looking for?

Sign in to comment.

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!