MATLAB: Number to datetime from textdata

convertdatenumdatetimenumber to datetime

Hi
I have this data that comes in a text document like this:
"%20180313123648396"
"%20180313123656586"
"%20180313123657351"
"%20180313123658552"
"%20180313123659316"
I need a way for matlab to read the numbers and then make it into a datetime.
So they would come out like:
13-03-2018 12:36:48
13-03-2018 12:36:57
13-03-2018 12:36:57
13-03-2018 12:36:59
13-03-2018 12:36:59
How do I do that? I know how to remove the % sign, but i cant make a number into a datetime, I've tried to sat the InputFormat to: yyyyMMDDHHMMSS but it cannot read it.
Please help

Best Answer

If I put your exact text in a file then
>> fmt='%{%yyyyMMddHHmmssSSS}D'
fmt =
%{%yyyyMMddHHmmssSSS}D
>> fid=fopen('mikkel.dat');
>> d=textscan(fid,fmt,'collectoutput',1)
d =
cell
[5×1 datetime]
>> fid=fclose(fid);
>> d=d{:}
d =
5×1 datetime array
%20180313123648396
%20180313123656586
%20180313123657351
%20180313123658552
%20180313123659316
>> d.Format='default'
d =
5×1 datetime array
13-Mar-2018 12:36:48
13-Mar-2018 12:36:56
13-Mar-2018 12:36:57
13-Mar-2018 12:36:58
13-Mar-2018 12:36:59
>>