No BSD License  

Highlights from
meet the family

image thumbnail
from meet the family by nathan q
Visualisation of a family tree in the programming contest.

filterBlanks(parent,nULines)
function [blanks,parent] = filterBlanks(parent,nULines)

n = numel(parent);

blanks = find(nULines==0);

for j=1:numel(blanks)
    i=blanks(j);
    % i is going to be deleted. 
    % We need to assign parents to the children of i,if any
    c = find(parent==i);
    if any(c)
        % go back through parents til we find a parent that exists and is not empty
        p = parent(i);
        while p>0 && nULines(p)==0 
            p = parent(p);
        end
        for k=1:numel(c)
            parent(c(k)) = p;
        end
    end
end

return

Contact us at files@mathworks.com