1

I am currently doing a project that involves MATLAB and I just can't seem to figure out a way to solve this problem. I have a data set that looks like this:

   262    23    34
   262    23    34
   262    23    35
   262    23    38
   262    23    38
   262    23    39
   262    23    40
   262    23    41
   262    23    42
   262    23    43
   262    23    45
   262    23    46
   262    23    47
   262    23    48
   262    23    50
   262    23    50
   262    23    51
   262    23    52
   262    23    55
   262    23    57
   262    23    58
   263     0     0
   263     0     2
   263     0     4
   263     0     7
   263     0    10
   263     0    15
   263     0    25
   263     0    29
   263     0    32
   263     0    39
   263     1     1
   272    23    28
   272    23    30
   272    23    56
   273     0     1
   273     0     2
   273     0     3
   273     0     3
   273     0     4
   273     0     4
   273     0     5
   273     0     5
   273     0     6
   273     0     8
   273     0    10
   273     0    32
   273     0    37

From the left to the right represents Julian day, hour in UTC, and minute when a tip of a rain gauge was made.

I need to calculate 5 minute totals and its accumulation of each day, for example, on the day 262 the rain tips total from 13-15 minute (since the information before 23:34 is not provided), 13-20 accumulated, 13-25, 13-30,... etc. Like I said each time recorded is when one tip was made and the precipitation amount of one tip is 0.01 inch. So all I need to know is how many tips were made within one day in 5 minute interval.

Could anyone help me please?

Amro
  • 123,847
  • 25
  • 243
  • 454
weathergirl
  • 41
  • 1
  • 6
  • Oooops, they are three different columns of day, hour, and minute – weathergirl Jul 04 '13 at 21:02
  • 1
    I'm thinking [`accumarray`](http://www.mathworks.com/help/matlab/ref/accumarray.html) can help here, but I'm still not sure what is the result you expect? – Amro Jul 04 '13 at 21:09
  • I am expecting to see, for example, on day 262 from the very beginning of the dataset provided the number of tips made during 23:34-35 (because the data chart doesn't give us any info about the tips until 23:34), # of tips during 23:34-40, 23:34-45,..., on day 263, 0:0-5, 0:0-10,...,etc. Does it make sense? :( – weathergirl Jul 04 '13 at 21:15
  • so you want to divide the day into 5 minutes intervals, and count how many "reads" you have in each bin, then take the cumulative sum. correct? – Amro Jul 04 '13 at 21:22
  • Yes sir!!! Sorry I'm bad at explaining – weathergirl Jul 04 '13 at 21:25
  • use `histc` to bin the counts – Shai Jul 04 '13 at 21:36
  • What I did is m=x(:,4); % m is minute of the hour in UTC, M=m'; M=[0, M, 0]; locations = find(diff(M)~=0); first_column = M(locations(2:end)); second_column = diff(locations); MM = [(first_column)', (second_column)'] But it only gives me how many times the same "minute" number appeared consecutively. I still don't know how to group them into 5 minutes intervals and get the cumulative sum. – weathergirl Jul 04 '13 at 21:41
  • possibly related question: [compute mean of each 1-minute interval of a time-series](http://stackoverflow.com/q/2323031/97160) – Amro Jul 04 '13 at 22:18

2 Answers2

1

you can convert day-hour-min into minutes. Suppose your data is stored in an n-by-3 matrix called data (how original). Then

 >> minutes = data * [24*60; 60; 1]; % counting minutes from the begining

Now you have to define the bins' edges (the intervals for summation):

 >> edges = min(minutes) : 5 : max(minutes); % you might want to round the lower and upper limits to align with a 5 minute interval.

Use histc to count how many drops in each bin

 >> drops = histc(minutes, edges); 
Shai
  • 111,146
  • 38
  • 238
  • 371
1

Perhaps something like this:

%# all possible days represented in the data
%# (you could also do this for all 1:365 days)
days = unique(X(:,1));

%# cumulative counts in each 5 minutes intervals
%# (each column represents one of the days)
counts = zeros(24*60/5,numel(days));


for i=1:numel(days)
    %# indices of the instances in that day
    idx = (X(:,1) == days(i));

    %# convert hour/minute into minute units
    m = X(idx,2).*60 + X(idx,3);

    %# count occurences in each 5 minute bin
    c = accumarray(fix(m/5)+1, 1, [24*60/5 1]);

    %# take the cumulative sum and store it
    counts(:,i) = cumsum(c);
end

so for day=262 we have:

>> counts(end-6:end,1)
ans =
     0    %# [00:00, 23:30)
     2    %# [00:00, 23:35)
     6    %# [00:00, 23:40)
    10    %# [00:00, 23:45)
    14    %# [00:00, 23:50)
    18    %# [00:00, 23:55)
    21    %# [00:00, 00:00 of next day)
Amro
  • 123,847
  • 25
  • 243
  • 454