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
This commit is contained in:
andrew@webrtc.org 2011-12-08 20:56:53 +00:00
parent b0be7aa7ae
commit c853aa1735

View File

@ -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