Add values to reference time

1 次查看(过去 30 天)
Hello I have the following code below. LoD shows 3 diffrent reference times. tim is the time vector. I wish to add tim to each of the LoDs to generate 3 different sets of times. The problem is that when i try to add tim to a LoD the values in tim with decimal places are truncated. eg 0.5 is truncated to 0 and 1.5 is truncated to 1 and so on. How could i suppress the truncation while using every value in tim. How can i output the results from this loop. Kindly advise
LoD = ['2006-01-10 18:20:12'; '2006-02-14 14:25:10'; '2006-03-17 11:13:14'];
tim = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4];
for x= 1:length(LoD)
newdates = datestr(addtodate(datenum(LoD(x,1:19)), length(tim), 'sec'));
end

采纳的回答

Walter Roberson
Walter Roberson 2020-7-16
LoD = ['2006-01-10 18:20:12'; '2006-02-14 14:25:10'; '2006-03-17 11:13:14'];
tim = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4];
basetimes = datetime(LoD);
temp = arrayfun(@(T) T+seconds(tim), basetimes, 'uniform', 0);
newdates = vertcat(temp{:});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by