Reputation: 29
I have a vector (X) of 525599. Each value represent every minute of the year 2010 (365 days). Let's clarify:
X date
1 1/1/2010 00:01:00
2 1/1/2010 00:02:00
3 1/1/2010 00:03:00
...
525599 31/12/2010 23:58:00
525599 31/12/2010 23:50:00
How can I convert the consecutive numbers in X in a format similar to the second column (DDMMYYYY HH:MM)?
Upvotes: 1
Views: 42
Reputation: 45741
If you have MATLAB version 2014b or later, then the simplest and best option is to make use of the new datetime
datatype:
datetime('2010-01-01') + minutes(X)
On older versions use:
datestr(datenum('2010-01-01') + X/(24*60))
Upvotes: 1
Reputation: 4510
An alternative way is to take your time as Epoch and then convert it into date time:
epoch_mil = 1262304000000 + X*1000*60; % 2010/01/01 00:00:00.000 + your Minutes
reference = datenum('1970', 'yyyy');
time = reference + epoch_mil / 8.64e7;
time_as_string = datestr(time, 'yyyy/mm/dd HH:MM:SS')
>> X = 1:4;
time_as_string =
2010/01/01 00:01:00
2010/01/01 00:02:00
2010/01/01 00:03:00
2010/01/01 00:04:00
Upvotes: 0