%% 
K = 10;
cvp = cvpartition(size(out_ridici,1),'kfold',K);
Predresult = zeros(size(out_ridici));
% out_matice = zscore(out_matice);
NumberOfFeatures = 8;
usedFeatures = 0;
myvariousFeatures = false(NumberOfFeatures,1);
prev_min = 1;
for m=1:2^NumberOfFeatures
usedFeatures = de2bi(m-1,NumberOfFeatures);
for a= 1:NumberOfFeatures
    
    myvariousFeatures(a) = usedFeatures(a) == 1;
    
end    
% Error(m) = tvoja_funkcia_pre_určenie_chyby(UsedFeatures);
if ~any(myvariousFeatures) 
    continue
end
for k=1:K
    Xtrain = out_matice(cvp.training(k),myvariousFeatures);
    Ttrain = out_ridici(cvp.training(k));
    mdl = fitcdiscr(...
    Xtrain, ...
    Ttrain, ...
    'DiscrimType', 'linear', ...
    'Gamma', 0, ...
    'FillCoeffs', 'off', ...
    'ClassNames', [2; 5; 69; 74]);
    Xtest = out_matice(cvp.test(k),myvariousFeatures);
   Ttest = out_ridici(cvp.test(k));
    Predresult(cvp.test(k)) = mdl.predict(Xtest);
    
end

 Error(m-1) = sum(out_ridici ~= Predresult)/size(out_ridici,1);

minError = min(Error);

if minError < prev_min
    Predresult_min = Predresult;
    Used_min_features = usedFeatures;
    prev_min = minError;
end
end
priznaky = [('Integralni kvadr. kriterium'); ...
            ('Integralni abs. kriterium  ');... 
            ('Integralni kriterium ITAE  '); ...
            ('Reakcni cas                '); ...
            ('Doba nabehu                '); ...
            ('Doba pretlumeni            ');...
            ('Zesileni                   '); ...
            ('Perioda                    '); ...
            ('Tlumeni                    ')];
Pouzite_priznaky = priznaky(Used_min_features==1,:);
clf
stem(out_ridici, 'LineWidth' ,1.5)
hold on
grid on
stem(Predresult_min, 'LineWidth', 1.5)
xlabel('Číslo prvku [-]','LineWidth', 1.5)
ylabel('Číslo řidiče [-]','LineWidth', 1.5)
legend('Správní řidiči', 'předpovězení rozpoznání')
Procento_uspesnosti = 100 - prev_min*100;
% Error = sum(out_ridici ~= Predresult)/size(out_ridici,1);

% 





