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

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

I just updated my code which may give you a bit clear picture.
R=zeros(365,30); % Space for the data
P_data=P(:,4); % Preciptation data
n=length(P_data);
C=1;
W_days=0;
for i=1:30;
for j=1:365;
R(j,i)=P_data(C);
C=C+1;
end
if R(j,i)>0;
W_days=W_days+1;
end
prob(j)=W_days/30; % probability of wet days
end
plot(1:365,prob)
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

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).
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

Asked:

on 25 Nov 2014

Edited:

dpb
on 26 Nov 2014

Community Treasure Hunt

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

Start Hunting!