dateN = datenum('03-Sep-2014 15:26:10');
total15minsamps = 4*24*4;
DATA = zeros(total15minsamps,7);
for ind = 1:total15minsamps
data= 10+5*sin(2*pi/12*ind);
dateN = addtodate(dateN,15,'minute');
Dvect = datevec(dateN);
DATA(ind,:) = [Dvect data];
end
Dates = DATA(:,1:6);
Flow = DATA(:,end);
QuarterH_Time = datenum(DATA(:,1:end-1));
[unDates, HourSep, subs] = unique(Dates(:,1:4),'rows');
Hour_Data=[unDates accumarray(subs, Flow, [], @mean)];
Hour_AVG_flow=Hour_Data(:,5);
Hour_Time=datenum([Hour_Data(:,1:4) zeros(length(Hour_Data),2)]);
[unDates, DaySep, subs] = unique(Dates(:,1:3),'rows');
Day_Data=[unDates accumarray(subs, Flow, [], @mean)];
Day_AVG_flow=Day_Data(:,4);
Day_Time=datenum(Day_Data(:,1:3));
Day_Time = Day_Time + QuarterH_Time(1)-Day_Time(1);
DaySep = [DaySep;length(Flow)+1];
DeltaFlow = zeros(size(Flow));
for ind =1:length(DaySep)-1
POI = DaySep(ind):DaySep(ind+1)-1;
DeltaFlow(POI)=Flow(POI)-Day_AVG_flow(ind);
end
figure,plot(Hour_Time,Hour_AVG_flow,Day_Time,Day_AVG_flow,QuarterH_Time,DeltaFlow);
legend('Hourly Flow','Daily Flow','15 min data - day average','location','best');
datetick ('x', 'mm-dd-yy', 'keepticks')
xlabel('Time');
ylabel('Flow [cfs]');
title('Daily Flow');
Best Answer