How to convert decimal hour and calculate the average every 5 min?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Marcelo Duarte
am 15 Nov. 2013
Kommentiert: Marcelo Duarte
am 18 Nov. 2013
Hello all! I'm a beginner at Matlab and I need to solve a problem. First, I need to convert the UT columm from decimal hour to hour:minute:seconds. Then, I need to calculate every 5 minutes on average the ROT collumn and show the reply in a new matrix (hour:min:sec,rot mean).
Example:

e.g. UT (5.404)=0.404*60=24.252; 0.252*60=15.12 ,then UT(5.404)=5:24:15 hours:min:sec
Thanks in advance
Marcelo
2 Kommentare
Doug Hull
am 15 Nov. 2013
Why are you dropping the 0.004 in the first step?
>> [Y, M, D, H, MN, S] = datevec(5.404/24)
Y =
0
M =
0
D =
0
H =
5
MN =
24
S =
14.4000
Akzeptierte Antwort
Walter Roberson
am 16 Nov. 2013
sprintf('%02d:%02d', H, MN)
In order to show this "together" with the ROT, you will need to indicate the mechanism you wish to use to "show" it. Are you referring to a uitable() for example?
Ordinary numeric matrices cannot hold a combination of strings and numbers.
3 Kommentare
Walter Roberson
am 17 Nov. 2013
bin_num = 1 + floor(ut(:) * 60 / 5) - floor(ut(1) * 60 / 5);
max_bin_num = max(bin_num);
rot_quad = rot.^2;
rot_quad_mean5 = accumarray(bin_num, rot_quad(:), [], @mean);
rot_mean5 = accumarray(bin_num, rot(:), [], @mean);
rot_mean_quad5 = rot_mean5 .^ 2;
ROTI_5 = sqrt(rot_quad_mean5 - rot_mean_quad5);
first_date_vec = datevec(ut(1) * 24);
first_date_hour = first_date_vec(4);
first_date_min5 = floor(first_date_vec(5) ./ 5) .* 5;
first_date_ser = datenum([0 0 0 first_date_hour first_date_min5 0]);
bin_date_vecs = datevec(addtodate(first_date_ser, 5 * (0:max_bin_num-1), 'minute'));
ROTI_matrix = [bin_date_vecs(:,4), bin_date_vecs(:,5), ROTI_5];
Now, ROTI_matrix will be an array, first column the hour of each 5 minute interval, second column the minute of each 5 minute interval, third column the corresponding ROTI for the 5 minute interval.
Weitere Antworten (1)
Andrei Bobrov
am 17 Nov. 2013
k = rem(UT,1)*60;
tms = fix([UT,k]);
m = ceil(k/5)*5;
[~,b,ii] = unique(m);
out = [tms(b,:), accumarray(ii,ROT,[],@mean)];
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!