MATLAB: How to extract certain column of date-time data from a text file

datetimedlmreadsscanftextscanxlsread

I have a .cef text file and it is a mixture of strings and data. A part of the code is as below:
% more irrelevant description on top
DEPEND_0 = time_tags__C3_CP_EDI_EGD
end_variable = kine_flag__C3_CP_EDI_EGD
! END_CEFMERGE_INCLUDE = "C3_CH_EDI_EGD_DATASET.ceh"
!
DATA_UNTIL=EOF
!
2014-12-17T20:14:24.220514Z, 109.196, 1.526, 1, 0
2014-12-17T20:14:45.373833Z, 109.315, 0.763, 1, 0
2014-12-17T20:15:21.192066Z, 108.480, 0.763, 1, 0
2014-12-17T20:15:48.907884Z, 107.527, 0.763, 1, 0
2014-12-17T20:16:26.787885Z, 107.646, 0.763, 1, 0
2014-12-17T20:16:45.387492Z, 107.169, 0.763, 1, 0
2014-12-17T20:17:04.818033Z, 106.573, 0.763, 1, 0
2014-12-17T20:17:48.323033Z, 106.454, 0.763, 1, 0
...
I hope to extract the first column of the data, which are dates in ISO 8601 format, and use it to plot a graph. To do this my code have to neglect all the description above, as well as the remaining columns.
I have thought of using dlmread, textscan, xlsread, sscanf, fopen, but since the data type is date-time and it consists of integers and strings, it is quite a challenge to me.
2014-12-17T20:14:24.220514Z
2014-12-17T20:14:45.373833Z
2014-12-17T20:15:21.192066Z
2014-12-17T20:15:48.907884Z
2014-12-17T20:16:26.787885Z

Best Answer

And, w/ all you considered, you neglected probably the easiest... :)
Putting your first sample data into a file I named 'jie.dat',
t=readtable('jie.dat','headerlines',7);
t.DT=datetime(t.Var1,'InputFormat','uuuu-MM-dd''T''HH:mm:ss.SSSSSSZ','TimeZone','UTC');
t.DT.Format=[t.DT.Format '.SSSSSS'];
The result of the above is...you can, of course, remove any variables not needed...
>> t
t =
8×6 table
Var1 Var2 Var3 Var4 Var5 DT
_____________________________ ______ _____ ____ ____ ___________________________
'2014-12-17T20:14:24.220514Z' 109.2 1.526 1 0 17-Dec-2014 20:14:24.220514
'2014-12-17T20:14:45.373833Z' 109.31 0.763 1 0 17-Dec-2014 20:14:45.373833
'2014-12-17T20:15:21.192066Z' 108.48 0.763 1 0 17-Dec-2014 20:15:21.192066
'2014-12-17T20:15:48.907884Z' 107.53 0.763 1 0 17-Dec-2014 20:15:48.907884
'2014-12-17T20:16:26.787885Z' 107.65 0.763 1 0 17-Dec-2014 20:16:26.787885
'2014-12-17T20:16:45.387492Z' 107.17 0.763 1 0 17-Dec-2014 20:16:45.387492
'2014-12-17T20:17:04.818033Z' 106.57 0.763 1 0 17-Dec-2014 20:17:04.818033
'2014-12-17T20:17:48.323033Z' 106.45 0.763 1 0 17-Dec-2014 20:17:48.323033
>>
ADDENDUM:
function n=readHdrLines(filename)
fid=fopen(filename,'r'); % open file...ensure filename fully-qualified name or in path
% do error checking here for valid fid
n=0; % initialize counter
while ~feof(fid) % loop until find key phrase
n=n+1; % increment line counter
if contains(fgetl(fid,'DATA_UNTIL=EOF')), break, end % found it; quit
end
n=n+1; % account for the comment line after before first data
fid=fclose(fid); % close the file
end
then just fixup the above sample code to something like--
filename=fullfile(yourpath,yourfile);
nHdr=readHdrLines(filename);
t=readtable('jie.dat','headerlines',nHdr);
...
ADDENDUM 2:
The grep utility will do this a whole lot faster; and can also be done with regexp if have file in memory. Don't know how that would compare to fgetl, but the portion of the file header section isn't that long so performance won't be terribly slow however you choose to do it.