How to plot average day from monthly data

1 次查看(过去 30 天)
Hi!
I have monthly data containing vehicle's flow (vehicles/min) during one month. How can I get one plot showing the average vehicles per minute during the day. In other words, I need to plot the average flow (veh/min) every minute in an average day.
my data looks something like this
Flow - timestamp
23veh - 01/01/14 00:00
24veh - 01/01/14 00:01
17veh - 01/01/14 00:02
32veh - 01/01/14 00:03
...
14veh - 01/01/14 23:59
19veh - 02/01/14 00:00
25veh - 02/01/14 00:01
...
24veh - 31/01/14 23:59
Thank you in advance for your help
  3 个评论
Abraham
Abraham 2014-4-10
Hi
The data is similar but not exactly, the flow data is a vector (double) and the date-stamp is a string.
Thanks
dpb
dpb 2014-4-10
See below...it's no problem, it's an ASCII file. I pasted a few lines of your posted file and tested the read, even.

请先登录,再进行评论。

回答(2 个)

dpb
dpb 2014-4-10
[v,d,m,y,h,mn]=textread('abe.dat','%dveh - %2d/%2d/%2d %2d:%2d','headerlines',1);
vbar=mean(reshape(v,24*60,[]));
plot(vbar)
Ain't Matlab easy (and fun) ??? :)

Azzi Abdelmalek
Azzi Abdelmalek 2014-4-12
fid=fopen('file.txt')
data=textscan(fid,'%s %s %s %s')
fclose(fid)
flow=cellfun(@(x) str2double(regexp(x,'[0-9]+(\.)?([0-9]+)?','match')),data{1},'un',0)
date1=cellfun(@(x,y) [x ' ' y],data{3},data{4},'un',0)
date2=datevec(date1,'dd/mm/yy HH:MM')
a=date2(:,1:3)
[ii,jj,kk]=unique(a,'rows')
b=accumarray(kk,cell2mat(flow),[],@mean)
f=cellstr(datestr([ii zeros(size(ii,1),3)],'dd/mm/yyyy'))
out=[f num2cell(b) ]

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by