【发布时间】:2026-01-31 17:20:02
【问题描述】:
我有一个温度向量和一个日期/时间元胞数组。我想创建 4 个变量,其中每个变量代表一天中的不同阶段。例如,我需要为整个 09:00 - 15:00、15:00-21:00、21:00-03:00 和 03:00-09:00 之间记录的所有温度创建变量年。
因此,如果一年中每小时记录一次温度,我将进行 8760 次测量,我想将其分解为与上述时间相对应的单独变量。
clear all
StartDate = '2011-01-01 00:00';
EndDate = '2011-12-31 23:57';
Resolution = 60;
DateTime=datestr(datenum(StartDate,'yyyy-mm-dd HH:MM'):Resolution/(60*24):...
datenum(EndDate,'yyyy-mm-dd HH:MM'),'yyyy-mm-dd HH:MM');
DateTime=cellstr(DateTime);
data = 1 + (20-1).*rand(8760,1);
所以,最后我将有一个变量,其中包含全年每天拍摄的这些时间之间的温度。
目前我正在使用 datevec 将 DateTime 转换为向量,然后使用:
P1{i}( not( 3 <= DateVector(:,4) & DateVector(:,4) < 9 ) ) = nan;
指定一天中的不同时间。这是完成此类任务的最佳方法吗?
【问题讨论】: