Averaging minute data to hour data
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Moses Joseph
le 19 Mar 2020
Commenté : Star Strider
le 9 Avr 2020
Greetings all.
My name is Joseph Moses.
I would like this great house to help me on how to average my data into hour and the hourly averaged data into daily.
For instance,
1.How do i get the corresponding average of 0.00:0.983, 1.000:1.983 till 23.00:23.983 in the second column (VTEC Data) from the below data or the attached.
2. Then plot the result Time against VTEC
1 commentaire
Ameer Hamza
le 19 Mar 2020
No need to include the complete txt file in the question. I have deleted to make the question readable.
Réponse acceptée
Star Strider
le 19 Mar 2020
Modifié(e) : Star Strider
le 19 Mar 2020
Try this:
D = load('bjcoo001-2015-01-01.txt');
M = ceil(D(:,1)+1E-4);
HrMeans = accumarray(M, (1:numel(M)).', [], @(x){mean(D(x,2:4))});
Result = [(0:23).' cell2mat(HrMeans)]
figure
plot(Result(:,1), Result(:,2))
grid
xlabel('Time')
ylabel('VTEC')
producing:
Result =
0 10.8497 2.0272 6.3800
1.0000 8.4937 1.8062 6.3800
2.0000 7.6810 1.1152 6.3800
3.0000 6.0948 1.0160 6.3800
4.0000 3.7198 1.0692 6.3800
5.0000 3.0660 1.1472 6.3800
6.0000 8.8583 0.9718 6.3800
7.0000 18.5332 1.1425 6.3800
8.0000 26.3258 1.4597 6.3800
9.0000 32.8312 1.5363 6.3800
10.0000 39.3363 1.9443 6.3800
11.0000 45.3585 3.1638 6.3800
12.0000 49.2812 3.2907 6.3800
13.0000 51.2610 2.2868 6.3800
14.0000 53.3373 2.2015 6.3800
15.0000 49.9703 4.1498 6.3800
16.0000 45.2548 3.5810 6.3800
17.0000 37.1800 3.4638 6.3800
18.0000 24.5763 3.7843 6.3800
19.0000 16.1022 4.9532 6.3800
20.0000 14.7298 3.7925 6.3800
21.0000 14.8348 4.0482 6.3800
22.0000 13.5453 3.9738 6.3800
23.0000 14.4595 5.1812 6.3800
EDIT —
Added plot image —
6 commentaires
Plus de réponses (1)
Ameer Hamza
le 19 Mar 2020
Modifié(e) : Ameer Hamza
le 19 Mar 2020
Try this
M = readmatrix('bjcoo001-2015-01-01.txt');
time = t(:,1);
hours = floor(time);
hour_average = splitapply(@(x) mean(x(:, 2:end), 1), M, hours+1);
hour_average = [unique(hours) hour_average];
plot(hour_average(:,1), hour_average(:,2:4));
2 commentaires
Ameer Hamza
le 23 Mar 2020
I guess you are using a release older than R2019a. readmatrix was added in R2019a.
Voir également
Catégories
En savoir plus sur Data Type Conversion 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!