
function [trainingSet, testSet] = splitData(data, partitioning)

division = [];
for i=1:length(data(:,1))
    
    if isempty(division)
        division = [division; data(i,end) {i}];
    else
        row = find(cell2mat(division(:,1))==data(i,end));
        
        if isempty(row)
            division = [division; data(i,end) {i}];
        else
            division(row,2) = {[cell2mat(division(row,2)) i]};
        end
    end
end

trainingSet = [];
testSet = [];
for i=1:length(division(:,1))
    a = cell2mat(division(i,2));
    division(i,2) = {a(randperm(length(a)))};
    
    a = cell2mat(division(i,2));
    split = floor(length(a)*partitioning);
    
    trainingSet = [trainingSet a(1:split)];
    testSet = [testSet a(split+1:end)];

end