我想计算这样的数据的经过时间(以毫秒为单位):
开始:2013-05-04 23:13:06.188 结束
:2013-05-05 1:22:41.617
我不能使用etime()
,因为我需要以毫秒为单位的经过时间。当我对这样的事情使用 for 循环时:
[start_i, end_i] = regexp(data{i}, '\d+-\d+-\d+ \d+:\d+:\d+.\d+');
temp_str = data{i};
time{i} = cellstr(temp_str(start_i:end_i));
n1 = datenum(datevec(time{i-1}, 'yyyy-mm-dd HH:MM:SS.FFF'));
n2 = datenum(datevec(time{i}, 'yyyy-mm-dd HH:MM:SS.FFF'));
n = n2 - n1
它给出了以下错误:
使用 dtstr2dtvecmx
时出错 将日期字符串转换为日期编号失败。datevec 中的错误(第 118 行)
y = dtstr2dtvecmx(t,icu_dtformat);测试错误(第 40 行)
n1 = datenum(datevec(time{i-1}, 'yyyy-mm-dd HH:MM:SS.FFF'));
如果我datevec()
这样使用:
[start_i, end_i] = regexp(data{i}, '\d+:\d+:\d+.\d+');
temp_str = data{i};
time{i} = cellstr(temp_str(start_i:end_i));
t1 = datevec(time{i-1}, 'HH:MM:SS.FFF');
t2 = datevec(time{i}, 'HH:MM:SS.FFF');
t = t2 - t1
datevec(t)
它正在逐个元素地减少时间段(秒与秒,分钟与分钟等),有时会给出负数。
我认为应该有一种巧妙的方法来做到这一点,而无需手动修复负值。有人知道该怎么做吗?