MATLAB: How to read multiple time (HH:MM) values from a text file

text file time

Hi,
I have a text file of the following format:
00:56 UserA
02:00 UserB
01:10 UserC
The first column is in HH:MM.
I would like to convert the first column to a numeric matrix which should contain numeric values in minutes, i.e.
[56; 120; 70]
The second column should be a cell array of strings.
I could do this totally manually, e.g. perform string manipulation one line at a time and extract this info (using textscan). But are there any built in functions to perform this?
Thanks! Sandy

Best Answer

There is no built-in function to do this, but you certainly don't need to do the string manipulation one line at a time:
c = textscan(fid, '%s %s');
hourminute = regexp(c{1}, '\d+', 'match');
minutes = cellfun(@(hm) str2num(hm{1}) * 60 + str2num(hm{2}), hourminute)';
users = c{2};