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

조회 수: 5 (최근 30일)
Hydro
Hydro 2014년 11월 25일
편집: dpb 2014년 11월 26일
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
Image Analyst
Image Analyst 2014년 11월 25일
Yes, but you still didn't attach P, or give code to read it in.

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2014년 11월 25일
편집: dpb 2014년 11월 26일
Leap years not accounted for?
If not, as the above would indicate, then
R=reshape(P_Data,365,[])>0;
  댓글 수: 2
Hydro
Hydro 2014년 11월 25일
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 2014년 11월 25일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by