How to plot average day from monthly data

2 vues (au cours des 30 derniers jours)
Abraham
Abraham le 10 Avr 2014
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 commentaires
Abraham
Abraham le 10 Avr 2014
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 le 10 Avr 2014
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.

Connectez-vous pour commenter.

Réponses (2)

dpb
dpb le 10 Avr 2014
[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 le 12 Avr 2014
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) ]

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by