Filter löschen
Filter löschen

joining two different datetime arrays

7 Ansichten (letzte 30 Tage)
AA
AA am 4 Nov. 2016
Beantwortet: Walter Roberson am 4 Nov. 2016
Assume
datetime({'Mon, Apr-25-16';'Fri, Mar-25-1'},'InputFormat','eee, MMM-dd-yy')
datetime({'13:00; 14:23'},'InputFormat','eee, hh:MM')
how do I join both datetime arrays so that they become one?
  2 Kommentare
Jan
Jan am 4 Nov. 2016
What is a wanted output? Should the times be added to the dates, of do you expect a set of 4 date&time values?
AA
AA am 4 Nov. 2016
yes it should be added to the dates and the output should be a datetime array file because I want to later on use it in a candle stick chart. Thanks

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Nick Counts
Nick Counts am 4 Nov. 2016
Bearbeitet: Walter Roberson am 4 Nov. 2016
You can use vertcat to combine your column arrays of datetime objects
vertcat( ...
datetime({'Mon, Apr-25-16';'Fri, Mar-25-1'}, 'InputFormat','eee, MMM-dd-yy'), ...
datetime({'Mon, Apr-25-16';'Fri, Mar-25-1'}, 'InputFormat','eee, MMM-dd-yy') )
might point you towards a solution?
Good luck!

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 4 Nov. 2016
datetime() objects are not good for representing "naked" time-of-day, because the date chosen for them will not be relative to Jan 1, year 0, but instead will be taken relative to the date at the time the datetime() conversion is done. So parsing '14:23' would be taken to be '14:23 today". It would result in a full datetime object, and you cannot add datetime objects -- you cannot say datetime('31-03-2008') + datetime('14:23') to get '31-03-2008 14:23'.
On order to put together a datetime that represents a date and a datetime that represents a time of day, you need to convert the time of day to a duration from the beginning of the day, and then you can add the duration to the datetime that represents the date. You can do that with dateshift()
Date_and_time_together_datetime = Time_of_day_datetime - dateshift(Time_of_date_datetime, 'begin', 'day') + Date_datetime;

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by