0

I have used the script below to read in my data (Sample below) and am able to compute the hourly and daily mean of Heat flux (H) by use of accumarraying the date and time stamps. The difficulty is that I also want to accumarray for 15 minute, 30 minute etc averages. How can one do this with the kind of data I have ?

 LASfile=fopen('../../data/heat.txt');
    Data = textscan(LASfile, '%16c %*24c %s %s %f %f %f %d %d %d %d','headerlines',1);
    fclose(LASfile);
    H = Data {6};
    %%
    date_num = datestr(Data{1});
    formatIn = 'dd-mmm-yyyy HH:MM:SS';
    DateVector = datevec(date_num, formatIn);
    %%
    % Group by day and hour
    [unDates, ~, subs] = unique(DateVector(:,1:4),'rows');
    % Accumulate by day
    [unDates accumarray(subs, H, [], @mean)]; %computes hourly heat flux

     #timeStamp           date        time        Cn2         CT2         H
2012-02-07 11:56:00     2/7/2012    11:56:00    3.11E-13    3.64E-01    330.5
2012-02-07 11:57:00     2/7/2012    11:57:00    2.22E-13    2.60E-01    256.4
2012-02-07 11:58:00     2/7/2012    11:58:00    2.92E-13    3.42E-01    315.3
2012-02-07 11:59:00     2/7/2012    11:59:00    4.07E-13    4.77E-01    404.4
2012-02-07 12:00:00     2/7/2012    12:00:00    3.56E-13    4.17E-01    365.7
2012-02-07 12:01:00     2/7/2012    12:01:00    4.41E-13    5.17E-01    429.3
2012-02-07 12:02:00     2/7/2012    12:02:00    4.23E-13    4.96E-01    416.3
2012-02-07 12:03:00     2/7/2012    12:03:00    3.17E-13    3.72E-01    335.3
2012-02-07 12:04:00     2/7/2012    12:04:00    3.42E-13    4.00E-01    354.7
2012-02-07 12:05:00     2/7/2012    12:05:00    3.43E-13    4.02E-01    355.6
2012-02-07 12:07:00     2/7/2012    12:07:00    2.92E-13    3.42E-01    315.3
2012-02-07 12:08:00     2/7/2012    12:08:00    2.63E-13    3.09E-01    291.7
2012-02-07 12:09:00     2/7/2012    12:09:00    2.45E-13    2.87E-01    276.1
2012-02-07 12:10:00     2/7/2012    12:10:00    3.00E-13    3.52E-01    321.8
2012-02-07 12:11:00     2/7/2012    12:11:00    3.77E-13    4.42E-01    382
2012-02-07 12:12:00     2/7/2012    12:12:00    4.40E-13    5.16E-01    428.9
2012-02-07 12:13:00     2/7/2012    12:13:00    3.60E-13    4.22E-01    369.2
2012-02-07 12:14:00     2/7/2012    12:14:00    4.56E-13    5.35E-01    440.4
2012-02-07 12:15:00     2/7/2012    12:15:00    3.62E-13    4.24E-01    370.5
2012-02-07 12:16:00     2/7/2012    12:16:00    3.48E-13    4.07E-01    359.3
2012-02-07 12:17:00     2/7/2012    12:17:00    3.94E-13    4.62E-01    394.9
2012-02-07 12:18:00     2/7/2012    12:18:00    3.53E-13    4.14E-01    363.5
2012-02-07 12:19:00     2/7/2012    12:19:00    4.47E-13    5.24E-01    433.6
2012-02-07 12:20:00     2/7/2012    12:20:00    4.33E-13    5.07E-01    423.6
2012-02-07 12:21:00     2/7/2012    12:21:00    3.18E-13    3.73E-01    336
2012-02-07 12:22:00     2/7/2012    12:22:00    2.91E-13    3.41E-01    314.7
2012-02-07 12:23:00     2/7/2012    12:23:00    2.71E-13    3.17E-01    297.8
2012-02-07 12:24:00     2/7/2012    12:24:00    3.72E-13    4.36E-01    378.2
2012-02-07 12:25:00     2/7/2012    12:25:00    3.25E-13    3.81E-01    341.8
2012-02-07 12:26:00     2/7/2012    12:26:00    3.66E-13    4.29E-01    373.3
2012-02-07 12:27:00     2/7/2012    12:27:00    3.95E-13    4.63E-01    395.3
2012-02-07 12:28:00     2/7/2012    12:28:00    3.73E-13    4.37E-01    378.9
2012-02-07 12:29:00     2/7/2012    12:29:00    3.31E-13    3.89E-01    346.7
2012-02-07 12:30:00     2/7/2012    12:30:00    3.05E-13    3.57E-01    325.7
4

1 回答 1

0

You should include the fifth element of DateVector rounded to what you need. For example, to use 15-min periods:

DateVector2 = DateVector(:,1:5);
DateVector2(:,5) = floor(DateVector(:,5)/15);

And then you accumarray based on this DateVector2:

[unDates, ~, subs] = unique(DateVector2,'rows');
% Accumulate by day
[unDates accumarray(subs, H, [], @mean)]; %computes average heat flux
于 2013-10-10T09:14:05.540 回答