2

我是 Matlab 的初学者,我需要解决一个问题。首先,我需要将 UT 列从十进制小时转换为小时:分钟:秒。然后,我需要平均每 5 分钟计算一次 ROT 列,并在新矩阵中显示回复(小时:分钟:秒,rot 平均值)。

数据

UT(第 1 列)矩阵
5.4
5.404
5.408

ROT (column2) 一个矩阵

0.22

0.123

0.129

例如 UT (5.404)=0.404*60=24.252;0.252*60=15.12 ,则 UT(5.404)=5:24:15 小时:分钟:秒

提前致谢

马塞洛

4

2 回答 2

1

First convert decimal hour dates into serial dates where unity is a day:

serdates = [5.4;5.404;5.408]/24;

Then convert to string with datestr (this is however a cosmetic operation):

datestr(serdates,'HH:MM:SS')

Group observation in 5 minute bins (lb <= x < up):

ymdhms      = datevec(serdates);
[~,minbins] = histc(ymdhms(:,5),[0:5:60])

Group then by year, day, month, hour and 5 minute bins:

[untime,~,subs] = unique([ymdhms(:,1:4) minbins*5],'rows')

Accumulate rot:

rot5min = accumarray(subs,[0.22;0.123;0.129]);

And for fancier presentation collect into dataset with datestrings

dataset({ cellstr(datestr(datenum([untime,zeros(size(untime,1),1)]),31)),'Datetime'}, {rot5min 'ROT5min'})

ans = 
    Datetime                     ROT5min
    '0000-01-00 05:05:00'        0.472  
于 2013-11-16T13:54:49.727 回答
0

这会做。干杯。

function v=myfunction(ut,rot)
% ut is a vector of decimal hours
% rot is a vector of the same length as ut
% v is a matrix with rows of the form (hour, min, sec, rot5) where
%   rot5 is an average of rot over 5 min interval from 2.5 min in the past
%   to 2.5 min to the future.

m=numel(ut);

% input validation
assert(isvector(ut) && isvector(rot) && numel(rot)==m);

% array initialization
v=zeros(m,4);
utCopy=ut;

for i=1:m
    % calculate hour from decimal hour
    v(i,1)=floor(utCopy(i));

    % calculate minute from decimal hour
    utCopy(i)=(utCopy(i)-v(i,1))*60;
    v(i,2)=floor(utCopy(i));

    % calculate second from decimal hour, round to nearest integer
    utCopy(i)=(utCopy(i)-v(i,2))*60;
    v(i,3)=round(utCopy(i));

    % calculate 5 mins central average of rot
    % to get forward average just replace the logical indexing with
    % ut>=ut(i) & ut<=ut(i)+1/12
    v(i,4)=mean(rot(ut>=ut(i)-1/24 & ut<=ut(i)+1/24));
end

end
于 2013-11-16T11:41:41.520 回答