mean value for every one minute and time blanks between
1 次查看(过去 30 天)
显示 更早的评论
Hi all!
I have a matrix with two columns: time(hours) & temperature. But I have time blank between the measurements. I want to find mean value of temperature for every one minute (0.0167 hours), but if it found a time difference ti+1-ti>0.08, it will start the next minute from the value after the blank. These are my data:
12.353855 23.1
12.355585 24.5
12.357284 22.9
12.358982 23.8
12.360677 25.2
12.362379 22.5
12.364070 23.8
12.365759 24.2
12.367457 26.2
12.369162 25.9
12.370863 24.6
12.372571 26.7
12.374269 21.9
12.375964 24.8
12.377664 25.3
12.379358 22.7
12.381062 21.5
12.382759 25.9
12.384461 24.3
12.386174 27.9
12.387877 22.8
12.389589 27.9
12.391289 28.1
12.392999 28.5
12.394866 28.4
12.396653 25.4
12.398355 24.6
12.400059 27.9
12.401765 25.9
12.403478 24.9
12.405176 24.6
12.406878 25.1
12.408587 26.9
12.410285 27.2
12.411974 28.4
12.413673 28.1
12.415377 28.5
12.417084 28.3
12.418792 27.9
12.420502 27.5
12.422201 23.5
12.423905 25.7
12.425616 26.9
12.427327 28.4
12.429039 21.6
12.430742 24.8
12.548259 27.2
12.549967 29.1
12.551696 28.5
12.553411 26.2
12.555119 25.3
12.556835 25.6
12.558541 24.9
12.560253 24.7
12.561979 25.8
12.563707 25.1
12.565423 25.2
12.567127 26.9
12.568838 26.3
12.570549 26.9
12.572253 25.9
12.573960 24.3
12.575676 22.9
12.577389 23.6
12.579099 21.9
12.580812 26.9
12.582526 25.3
12.584236 26.7
12.585938 28.1
12.587654 27.8
12.589361 26.9
12.591072 25.9
12.592776 23.2
12.594488 26.8
12.596212 27.2
12.597924 29.8
12.599636 30.5
12.601343 33.8
12.603080 32.7
12.604791 31.9
12.606495 30.8
12.608208 29.7
12.609928 29.5
12.611652 28.8
12.613373 28.7
12.615088 28.5
12.616798 27.5
12.618511 25.9
12.620223 26.2
12.621948 25.9
12.623668 27.5
12.625381 28.3
12.627093 27.1
12.628804 26.2
12.746722 26.8
12.748493 27.9
12.750228 22.1
12.751951 27.9
12.753672 25.9
12.755397 24.6
12.757117 23.9
12.758842 22.8
12.760568 23.4
12.762300 24.1
12.764025 23.9
12.765754 23.6
12.767480 24.5
12.769198 24.7
12.770914 25.8
12.772649 26.7
12.774382 26.8
12.776115 25.2
12.777848 24.8
12.779577 25.2
12.781286 25.8
For example, after the value 46 there is a time blank, so i want the next minute will start from the value 47. Until the value 46 there are 5 minutes. 1:10, 11:20, 21:30, 31:40, 41:46 and then 47:56, 57:66, 67:76 and so on....
Any ideas??
Thank you!
0 个评论
回答(1 个)
Peter Perkins
2016-9-21
There are a variety of ways to do this, all more or less involving creating a grouping variable that says what minute each row of your data are from. From there, you can use things like varfun (on a table), splitapply, or accumarray to compute the means in each group.
Since R2014b, you could use durations to represent the elapsed time.
In the recently-released R2016b, you can use timetables to do this in one line of code:
% given t and x as the two columns of data, make a timetable
>> tt = timetable(x,'RowTimes',t)
tt =
Time x
_________ ____
12.354 hr 23.1
12.356 hr 24.5
12.357 hr 22.9
12.359 hr 23.8
12.361 hr 25.2
[snip, 110 more rows]
>> tt.Time.Format = 'm'
tt =
Time x
__________ ____
741.23 min 23.1
741.34 min 24.5
741.44 min 22.9
741.54 min 23.8
741.64 min 25.2
[snip, 110 more rows]
>> ttm = retime(tt,'minutely','mean')
ttm =
Time x
_______ ______
741 min 23.75
742 min 24.55
743 min 26.433
744 min 26.75
745 min 26.067
746 min NaN
747 min NaN
[snip, 19 more rows]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!