Filter löschen
Filter löschen

Add values to reference time

1 Ansicht (letzte 30 Tage)
Arthur Batte
Arthur Batte am 16 Jul. 2020
Kommentiert: Arthur Batte am 16 Jul. 2020
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Jul. 2020
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{:});

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by