mean value with time blanks

1 visualización (últimos 30 días)
Thar
Thar el 21 de Sept. de 2016
Editada: Andrei Bobrov el 21 de Sept. de 2016
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
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!

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 21 de Sept. de 2016
Editada: Andrei Bobrov el 21 de Sept. de 2016
Hi Thodoris! Let data - your data ( a matrix with two columns: time(hours) & temperature).
dff = [0;diff(data(:,1))];
tm = cumsum(dff);
% variant 1
t = 1/60;
i_1 = floor(tm/t)+1;
[Mly,~,i1] = unique(i_1);
out1 = [Mly,accumarray(i1,data(:,2),[],@mean)];
% variant 2 (use datevec)
[~,~,~,~,M] = datevec(tm/24);
[Mly,~,i2] = unique(M);
out2 = [Mly,accumarray(i2,data(:,2),[],@mean)];
% variant3 (use degrees2dms - function from Mapping Toolbox or her analog)
dms = degrees2dms(tm);
[Mly,~,i3] = unique(dms(:,2));
out3 = [Mly,accumarray(i3,data(:,2),[],@mean)];
content of m-file: degrees2dms.m
function dms = degrees2dms(angleInDegrees)
a = angleInDegrees(:);
m = rem(a,1)*60;
t = abs(m - round(m)) < eps(10e2);
m(t) = round(m(t));
dms = [fix(a),fix(m),round(60000*rem(m,1))/1000];
And for users of MATLAB 9.1 (work ?)
Time = hours(tm);
Temp = data(:,2);
T2 = timetable(Time,Temp);
out4 = retime(T2,'minutely','mean');

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by