Count the frequency of 2 consecutive days in a year
    7 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Dear all, 
I want to obtain the frequency of 2 consecutive days in a year based on the following conditions/steps:
- I have a variable (R_3) with the daily data during 1992-2022.
- For a single year, obtain the days > 95th percentile. The 95th percentile is based on the entire period (1992-2022).
- Determine if there are any consecutive days. I have used backward difference for this.
- Determine if the consecutive days fall into the category of 2 consecutive days. If not ignore it.
- Total count in (4). E.g., 2 consecutive days fall on the 1st, 2nd, & 5th, 6th. This would give me 2 counts of 2 consecutive days.
I have attached my code below. I am having trouble with steps 4 & 5 and do not know how to proceed.
clear; clc;
load('Sample.mat');
% % Estimate the number of days during 1992-2022 ==========================
yr1 = 1992;
yr2 = 2022;
yr = yr1:yr2;
d1 = yeardays(yr);                                                          % Number of days per year
d2 = [1 d1(1:end-1)];
t1 = cumsum(d2);
t2 = cumsum(d1);
y1 = R_3;
for i = 1:size(t1,2)
    a1{i,:} = find(y1(t1(i):t2(i)) > prctile(y1,95));                       % Days where y1 > 95th percentile
    a2      = cell2mat(a1(i));
    a3      = diff(a2);                                                     % Backward difference
    a4{i,:} = find(a3 == 1);                                                % 1 == consecutive day
end
Thank you very much for your help.
0 件のコメント
回答 (1 件)
  Parag Jhunjhunwala
      
 2023 年 6 月 24 日
        
      編集済み: Parag Jhunjhunwala
      
 2023 年 6 月 24 日
  
      Hi Eli
I have modified the for loop in your code to find out the count of exactly 2 consecutive days for each year and stored it in the vector a3.
for i = 1:size(t1,2)
    a1{i,:} = find(y1(t1(i):t2(i)) > prctile(y1,95));                       % Days where y1 > 95th percentile
    a2      = cell2mat(a1(i));
    count=0;
    a3(i) = 0; % Count exactly 2 consecutive days
    for j=2:length(a2)
        if(a2(j)-a2(j-1) == 1)
            count = count+1;
        else
            if(count == 1)
                a3(i) = a3(i)+1;
            end
            count=0;
        end
    end
    if(count == 1)
        a3(i) = a3(i)+1;
    end
end
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

