function tab1= levels_association(mat,tab)
%Crea le associazioni ai livelli successivi al primo
checked=[];
tab1=[];
for i=1:size(tab,2)
    if confronto(i,checked)==0
        best=element_scan(mat,tab,tab{1,i},i,checked);
        if best{2,1}~=0
            max_better.value=0;
            for s=1:size(best,2)
                if max_better.value<best{2,s}
                    max_better.value=best {2,s};
                    max_better.indexes=best{1,s};
                end
            end
            col{1,1}= max_better.indexes;
            col{2,1}= max_better.value;
            col{3,1}= cat(2,tab{3,max_better.indexes(1)},tab{3,max_better.indexes(2)});
            tab1=cat(2,tab1,col);
            checked=cat(2,checked,col{1,1});
        end
    end
end

if mod(size(tab,2),2)==1
   for s=1:size(tab,2)
      if confronto(s,checked)==0
         c{1,1}=s;
         c{2,1}=0;
         c{3,1}=tab{3,s};
         tab1=cat(2,tab1,c); 
      end
   end
end

    
