From c853aa173545e88543833eb3138a8b76d9264bf6 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Thu, 8 Dec 2011 20:56:53 +0000 Subject: [PATCH] Swap colheaders for textdata in parseLog.m. - colheaders doesn't appear in the struct returned from importdata for me. - Add a new error check for empty/malformed files. Review URL: http://webrtc-codereview.appspot.com/318001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1137 4adac7df-926f-26a2-2b94-8c16560cd09d --- tools/matlab/parseLog.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/matlab/parseLog.m b/tools/matlab/parseLog.m index 6cc455061d..5d4c3f7bc1 100644 --- a/tools/matlab/parseLog.m +++ b/tools/matlab/parseLog.m @@ -25,21 +25,30 @@ function parsed = parseLog(filename) % be found in the AUTHORS file in the root of the source tree. table = importdata(filename, ',', 1); +if ~isstruct(table) + error('Malformed file, possibly empty or lacking data entries') +end + +colheaders = table.textdata; +if length(colheaders) == 1 + colheaders = regexp(table.textdata{1}, ',', 'split'); +end + parsed = struct; i = 1; -while i <= length(table.colheaders) +while i <= length(colheaders) % Checking for a multi-value column. - m = regexp(table.colheaders{i}, '([\w\t]+)\[(\d+)\]', 'tokens'); + m = regexp(colheaders{i}, '([\w\t]+)\[(\d+)\]', 'tokens'); if ~isempty(m) % Parse a multi-value column n = str2double(m{1}{2}) - 1; parsed.(strrep(m{1}{1}, ' ', '_')) = table.data(:, i:i+n); i = i + n + 1; - elseif ~isempty(table.colheaders{i}) + elseif ~isempty(colheaders{i}) % Parse a single-value column - parsed.(strrep(table.colheaders{i}, ' ', '_')) = table.data(:, i); + parsed.(strrep(colheaders{i}, ' ', '_')) = table.data(:, i); i = i + 1; else - error('Error: Empty column'); + error('Empty column'); end end