function [ subtree ] = FindSubtree( subsets )
% Hassan Nahas
%This function is a recursive one that uses findbestx to build the decision
%tree depth first. NaN represents a leaf node. Trees are built using cells.
    subtree = cell(3,2);
    for i = 1:3
    
        
    
        if subsets{i,1} ~= 0
            [ bestx,resultingSubsets ] = findbestx( subsets{i,2},subsets{i,3} );
            subtree{i,1} = bestx;
            subtree{i,2} = FindSubtree(resultingSubsets);
        else
            subtree{i,1} = NaN;
            if ~(isempty(subsets{i,3}))
                subtree{i,2} = subsets{i,3}(1);
            else
                subtree{i,2} = NaN;
            end
        end
    end
end

