LoadEvents - Read events from file. USAGE events = LoadEvents(filename) filename event file name
0001 function events = LoadEvents(filename) 0002 0003 %LoadEvents - Read events from file. 0004 % 0005 % USAGE 0006 % 0007 % events = LoadEvents(filename) 0008 % 0009 % filename event file name 0010 0011 % Copyright (C) 2004-2015 by Michaƫl Zugaro 0012 % 0013 % This program is free software; you can redistribute it and/or modify 0014 % it under the terms of the GNU General Public License as published by 0015 % the Free Software Foundation; either version 3 of the License, or 0016 % (at your option) any later version. 0017 0018 events.time = []; 0019 events.description = []; 0020 if ~exist(filename), 0021 error(['File ''' filename ''' not found.']); 0022 end 0023 0024 % Read file into cell array 0025 file = fopen(filename,'r'); 0026 if file == -1, 0027 error(['Cannot read ' filename ' (insufficient access rights?).']); 0028 end 0029 c = textscan(file,'%s','delimiter','\n'); 0030 fclose(file); 0031 0032 % Parse cell array (extract time and messages using regular expressions) 0033 t = regexprep(c{1},'([^ \t]*).*','$1','once'); 0034 events.time = cellfun(@str2num,t); 0035 events.description = regexprep(c{1},'[^ \t]*[ \t]*','','once'); 0036 % t = regexprep(c{1},'([0-9]*[.]?[0-9]*[e]?[+-]?[0-9]*).*','$1','once'); 0037 % events.description = regexprep(c{1},'[0-9]*[.]?[0-9]*[ \t]*','','once'); 0038 0039 0040 % Convert to seconds 0041 if ~isempty(events.time), events.time(:,1) = events.time(:,1) / 1000; end