how to make hourly average
Afficher commentaires plus anciens
I have data in excel file The first column is date with format 1/01/2005 1:00 until 1/01/10 0:00 including 366 days on leap year. The second column is gas demand in cubic meters. What I want to ask are: 1. How to make average for each hour for every for month? (x=00.00-23.00; y= gas demand; curve = jan-april, may-august, and sept-dec). 2. How to make average for each day on the week?(x=Monday, Tuesday, Wednesday, ... Sunday; y=gas demand). Any help is appreciated. Thank you
1 commentaire
Jan
le 2 Juil 2013
Is this really an Excel file and do you want to perform the calculations in Matlab? Is "1/01/2005 1:00" a text string inside an CSV-file or the rqw data replied as 3rd output from XLSREAD? Did you import the file already?
Réponses (1)
Andrei Bobrov
le 4 Juil 2013
Modifié(e) : Andrei Bobrov
le 4 Juil 2013
h0 = cumsum(ones((datenum(2010, 1, 1)-datenum(2005, 1, 1))*24,1));
d0 = datenum(2005,1,1,h0,0,0); % Let your date
d2 = datevec(d0);
data = randi(125,numel(d0),1); % Let your data
[~,iI1] = histc(d2(:,2),[1 5 9 inf]);
valueI = accumarray([d2(:,4)+1, iI1],data,[],@mean); % first part of your question
iII = weekday(d0);
xII = mod(iII - 2,7)+1;
valueII = accumarray(xII,data,[],@mean); % second part of your question
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!