Looping and average through column values of a CSV
이전 댓글 표시
Hello All, i am relatively new to matlab so dont understand much.
I have a csv file with timeseries data taken every 6 seconds on a single day for 7 different parameters (all paramters are present in the csv as well).
I want to generate a method using for looping by which i can generate averages at every 1min, 5 mins, 1hours etc and plot those points as well.
My data loops something like this.
date & time x y z xa xb xc
02/05/2016 11:02:01 AM 101.3 42.8 22.6 102.3 95.5 57.9
02/05/2016 11:02:07 AM 99.8 49.7 22.1 142.9 103.4 61.6
02/05/2016 11:02:13 AM 1568.8 62.8 25.5 11407.1 2017 259.2
02/05/2016 11:02:19 AM 453.6 158 35.5 941.3 506.1 208.1
02/05/2016 11:02:25 AM 144.3 50.5 22.5 273.5 161.5 69.1
02/05/2016 11:02:31 AM 155.7 49.6 22.1 434.1 166.9 71.1
02/05/2016 11:02:37 AM 1265.4 51.5 35.9 4925.7 1565.9 188.5
02/05/2016 11:02:43 AM 249.3 111.4 28.5 281.7 246.4 145.8
02/05/2016 11:02:49 AM 379.6 76.2 24.9 888.9 429 125.9
02/05/2016 11:02:55 AM 197.9 42.5 23.3 499.8 204.3 66.9
02/05/2016 11:03:01 AM 174.1 84.6 58.9 234.6 178.8 103.1
02/05/2016 11:03:07 AM 153 81.5 50.8 441.5 157 100.8
02/05/2016 11:03:13 AM 154.3 72.7 36.8 228 153.7 88.5
02/05/2016 11:03:19 AM 91.8 49.6 23.2 91.8 90.8 64.9
02/05/2016 11:03:25 AM 117.7 51.7 24.2 127.7 113 66.4
02/05/2016 11:03:31 AM 115.8 57.2 23.6 137.9 120.1 77.3
02/05/2016 11:03:37 AM 119 53.6 22.6 319.8 124.9 71.8
02/05/2016 11:03:43 AM 85.2 47.6 24.7 90.3 83.8 59.2
02/05/2016 11:03:49 AM 122.2 53.3 24.3 165.3 126.4 73.8
02/05/2016 11:03:55 AM 174.4 71.9 26.7 269.8 180.4 95.1
02/05/2016 11:04:01 AM 587.2 44.5 25.7 2079 691.7 127.3
02/05/2016 11:04:07 AM 109.1 51.7 27.5 184.9 119.9 65.9
02/05/2016 11:04:13 AM 86.4 50.2 24.9 129.2 92.6 60.7
the data extends to nearly 2000 entries. Check the attached image for a proper format.
Can anyone help me out? thank you.
댓글 수: 2
Andrei Bobrov
2017년 7월 7일
Please attach your data as csv-file.
Dhwanilnath Gharekhan
2017년 7월 7일
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2017년 7월 7일
편집: Andrei Bobrov
2017년 7월 7일
For MATLAB >= R2016b
T = readtable('Data_test.csv');
a = datetime(T.date_time,'I','dd-MM-yyyy HH:mm');
T.date_time = a;
TT = table2timetable(T);
TT_mean_1minutes = retime(TT,'minutely','mean');
b = TT.date_time(1):minutes(5):TT.date_time(end);
or other variant for b
c = TT.date_time(1);
b = ((c - minutes(rem(minute(c),5))):minutes(5):T.date_time(end))';
TT_mean_5minutes = retime(TT,b,'mean');
TT_mean_1hour = retime(TT,'hourly','mean');
카테고리
도움말 센터 및 File Exchange에서 Time Series Collections에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!