I am trying to use the %{frmt}D syntax in textscan with a date, but am unable to get it to work, and instead observe unexpected behavior.
I have the following code. First, I define a date:
>> sTest = '[11-11-2016 17:08:53.453]; test~';
I then try match the %{frmt}D syntax to the date provided in 'sTest', and have the rest of it match to %q:
>> out1= textscan(sTest, '[%{MM-dd-yyyy HH:mm:ss.SSS}D]%q', 'Delimiter',{'~'});
Error using textscan
Unable to read the DATETIME data with the format 'MM-dd-yyyy HH:mm:ss.SSS'. If
the data is not a time, use %q to get text data.
>> out2 = textscan(sTest, '[%{MM-dd-yyyy HH:mm:ss.SSS}D]%q', 'Delimiter',{']','~'})
out2 =
1×2 cell array
[11-11-2016 17:08:53.453] {0×1 cell}
>> out3 = textscan(sTest, '[%{MM-dd-yyyy HH:mm:ss.SSS}D%q', 'Delimiter',{']','~'})
out3 =
1×2 cell array
[11-11-2016 17:08:53.453] {1×1 cell}
However, I get unexpected results, as seen above. The first case produces an error, the second does not pick up the second portion of the input, and the third case works, but I do not understand why. Can you explain what is happening?
Best Answer