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
diff --git a/tools/matlab/parseLog.m b/tools/matlab/parseLog.m
index 6cc4550..5d4c3f7 100644
--- a/tools/matlab/parseLog.m
+++ b/tools/matlab/parseLog.m
@@ -25,21 +25,30 @@
% 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