在matlab中创建包含时间的向量

在matlab中创建包含时间的向量,matlab,time,Matlab,Time,我有一个包含一天中小时数的单元格数组 hours = {'00:00:00', '01:00:00', '02:00:00', '03:00:00', '04:00:00', '05:00:00', '06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00', '12:00:00',... '13:00:00', '14:00:00', '15:00:00', '16:00:00', '17:00:00',

我有一个包含一天中小时数的单元格数组

hours = {'00:00:00', '01:00:00', '02:00:00', '03:00:00', '04:00:00', '05:00:00', '06:00:00', '07:00:00', '08:00:00', '09:00:00', '10:00:00', '11:00:00', '12:00:00',...
    '13:00:00', '14:00:00', '15:00:00', '16:00:00', '17:00:00', '18:00:00', '19:00:00', '20:00:00', '21:00:00', '22:00:00', '23:00:00'};
我手动创建了它:(…现在我想创建另一个间隔为15分钟的…您有没有自动创建的提示

hours_15 = {'00:00:00', '00:15:00','00:30:00',...,'23:45:00'}

您可以使用datenum实现这一点:

dt = datenum('00:15:00','HH:MM:ss') - datenum('00:00:00','HH:MM:ss'); % or: dt = 1/(24*4)
time_begin = datenum('00:00:00','HH:MM:ss');
time_end = datenum('23:45:00','HH:MM:ss');
hours_15 = cellstr(datestr(time_begin:dt:time_end,'HH:MM:ss'));

您可以使用datenum实现这一点:

dt = datenum('00:15:00','HH:MM:ss') - datenum('00:00:00','HH:MM:ss'); % or: dt = 1/(24*4)
time_begin = datenum('00:00:00','HH:MM:ss');
time_end = datenum('23:45:00','HH:MM:ss');
hours_15 = cellstr(datestr(time_begin:dt:time_end,'HH:MM:ss'));

一个非常简单但不那么优雅的解决方案:

hours = 0:23;
quarters = [0,15,30,45];
counter = 0;
% Pre-allocate space
C = cell(96,1)
for ii=1:24
    for jj=1:4
        counter=counter+1;
            C{counter} = sprintf('%02d:%02d:00',hours(ii),quarters(jj));
    end
end

需要注意的是,这需要Nras溶液四分之一的时间。

一个非常简单但不那么优雅的溶液:

hours = 0:23;
quarters = [0,15,30,45];
counter = 0;
% Pre-allocate space
C = cell(96,1)
for ii=1:24
    for jj=1:4
        counter=counter+1;
            C{counter} = sprintf('%02d:%02d:00',hours(ii),quarters(jj));
    end
end
应注意的是,这需要Nras溶液溶液四分之一的时间