I am looking to convert a cell array of dates to a datetime array. From the text file BUContactOutput.txt I need the Start Time and Stop time in separate datetime arrays. This section of code shows how I am going about creating the StartTime datetime array.
ContactData = readtable('BUContactOutput.txt',... 'Delimiter', ' ', 'HeaderLines',4);NumOfContacts = height(ContactData);StartTime = cell(NumOfContacts,1);for i = 1:NumOfContacts day = num2str(ContactData.Var1(i)); month = char(ContactData.Var2(i)); year = num2str(ContactData.Var3(i)); time = char(ContactData.Var4(i)); StartTime{i,1} = strcat(year,'-',month,'-',day,'-',time);enddatetime(StartContact, 'InputFormat', 'yyyy-MMM-dd-HH:mm:SSS')
This method is successful when the time component of StartTime is not included (no ,'-',time in the strcat function and no -HH:mm:SSS in datetime function), yet is not successful when the time component is included. I believe I have a syntax error in my 'InputFormat' content. I am unsure how to resolve the issue and the documentation has yet to provide me with a solution.
https://www.mathworks.com/help/matlab/ref/datetime.html#
Thanks ahead to anyone who offers help.
-Emil
Best Answer