Skip to content

Commit

Permalink
fixed bug dj.struct.tabulate (introduced in a recent commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitri-yatsenko committed Feb 11, 2014
1 parent 364e5fe commit f4f9b2c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions +dj/struct.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
n = length(indexFields);
assert(n>0)
ix = cell(n,1);
v = cell(n,1);
v = cell(n,1);
for i=1:n
if isnumeric(s(1).(indexFields{i}))
[v{i},~,ix{i}] = unique([s.(indexFields{i})]);
Expand All @@ -139,9 +139,9 @@
value = s(i).(valueField);
tab{ixx{:},j}=value;
end
if isnumeric(s(1).(valueField))
if all(arrayfun(@(s) isnumeric(s.(valueField)) && isscalar(s.(valueField)), s))
tab(cellfun(@isempty,tab))={nan}; % replace empties with nans
tab = cellfun(@double, tab); % convert all to double. cell2mat does not work if cells are of different types
tab = cellfun(@double, tab); % convert to double; cell2mat fails when cells of different numeric types
end
varargout = v';
end
Expand Down

0 comments on commit f4f9b2c

Please sign in to comment.