MATLAB: Datevec problem – not able to convert string to numeric array

chracterdatevechoursMATLABstring

Hi I have problem with datevec. I have vector like this. I am trying to parse data for obtaining second. But it always gives an error for me. I have my time vector in String Format in 2017a.
"2017-10-16T14:39:00.221Z"
"2017-10-16T14:39:02.221Z"
"2017-10-16T14:39:03.221Z"
"2017-10-16T14:39:04.221Z"
"2017-10-16T14:39:06.221Z"
"2017-10-16T14:39:08.221Z"
"2017-10-16T14:39:09.221Z"
"2017-10-16T14:39:10.221Z"
"2017-10-16T14:39:11.221Z"
The code that I write is
Time= strrep(Time, 'Z', ''); %find .XXXXZ replace to''
Time= strrep(Time, 'T', ' '); %find T replace to' '
formatIn = 'yyyy-mm-dd HH:MM:SS'
datevec(Time,formatIn)
The answer of matlab is
formatIn =
'yyyy-mm-dd HH:MM:SS'
Error using datevec (line 103) The input to DATEVEC was not an array of character vectors. What Can I do???

Best Answer

A = {'2017-10-16T14:39:00.221Z'
'2017-10-16T14:39:02.221Z'
'2017-10-16T14:39:03.221Z'
'2017-10-16T14:39:04.221Z'
'2017-10-16T14:39:06.221Z'
'2017-10-16T14:39:08.221Z'
'2017-10-16T14:39:09.221Z'
'2017-10-16T14:39:10.221Z'
'2017-10-16T14:39:11.221Z'};
Time = strung(A);
dt = datetime(regexprep(A,{'T','Z'},{' ',''}),'I','uuuu-MM-dd HH:mm:ss.SSS');
out = datevec(dt);