function [trainClasses,trainData]=balance2Classes(trainClasses,trainData)
    %balances two classes (0,1)
    eps=0.00001;
    while mean(trainClasses)> 0.5+eps || mean(trainClasses) < 0.5-eps
        r=floor(0.5*size(trainClasses)*rand(1)+1);
        if mean(trainClasses) < 0.5
            more=find(trainClasses==0);
        else
            more=find(trainClasses==1);
        end
        trainClasses=trainClasses([1:more(r)-1,more(r)+1:end]);
        trainData=trainData([1:more(r)-1,more(r)+1:end],:);
    end
end