次のように、ファイルを1行ずつ読み取り、必要なデータをセル配列に格納するだけです。
f_read = fopen('testcase.txt','r'); %The file 'testcase.txt' would contain the data of interest.
pat = '(?<datetime>[^;]*)(.*)'; %Regular expression to extract required field.
datetime = cell(0,1);
line = fgets(f_read);
while(line ~= -1) %Till the end of file.
line = regexp(line, pat, 'names'); %Extracts first column from input line.
datetime = [datetime;line.datetime]; %Append result as next row.
line = fgets(f_read);
end
入力の場合、結果は次のようになります。
>> datetime
datetime =
'23/7/1998 20:00'
'23/7/1998 21:00'
'23/7/1998 22:00'
'23/7/1998 23:00'
'24/7/1998 0:00'
'24/7/1998 1:00'
'24/7/1998 2:00'
'24/7/1998 3:00'
'24/7/1998 4:00'
個々のレコードには、次のようにアクセスできます。
>> datetime{1}
ans =
23/7/1998 20:00