%Rozdělení tabulky "Priznaky.xls" na čtyři tabulky "P_muz.xls","K_muz.xls",
%"P_zena.xls","K_zena.xls", podle toho zda se jedná o muže (parkinson x
%kontrolní), nebo ženu (parkinson x kontrolní).



clear all
clc


lab= {'7.1_1_a','7.1_1_e','7.1_1_i','7.1_1_o','7.1_1_u','7.1_2_a','7.1_2_e',...
    '7.1_2_i','7.1_2_o','7.1_2_u','7.1_3_a','7.1_3_e','7.1_3_i','7.1_3_o',...
    '7.1_3_u','7.1_4_a','7.1_4_e','7.1_4_i','7.1_4_o','7.1_4_u','ParkinsonPr'};

K = length(lab);  %pocet labelu v jednotlivych nahravkach
   for c = 1:K   %cyklus pro label  
     
  
[ndata, text, alldata] = xlsread('Priznaky.xls',lab{c});


z = strfind(text, 'P1'); %nalezeni parkinson zen
m = strfind(text, 'P2'); %nalezeni parkinson muzu
kz = strfind(text, 'K1'); %nalezeni kontrolich zen
km = strfind(text, 'K0'); %nalezeni kontrolich muzu


A1= z(2:end,1);
A2= m(2:end,1);
A3= kz(2:end,1);
A4= km(2:end,1);

L = length(A1);
M = length(A3);

  kl=[];
  lk=[];
  mn=[];
  nm=[];
for i=1:L

           if(A1{i} == 1)
               
              kl=[kl;ndata(i,:)];           
              %kl(isfinite(kl(:, 1)), :)  %vymazani hodnot NaN infinity
             kl(~any(kl,2),:)=[];    %vymazani nulovych hodnot z tabulky
           end    
             
           if(A2{i} == 1)
              lk=[lk;ndata(i,:)];           
              %lk(isfinite(lk(:, 1)), :)  %vymazani hodnot NaN infinity
              lk(~any(lk,2),:)=[];    %vymazani nulovych hodnot z tabulky   
           end
           
            if(A3{i} == 1)
              mn=[mn;ndata(i,:)];           
             % mn(isfinite(mn(:, 1)), :)  %vymazani hodnot NaN infinity
              mn(~any(mn,2),:)=[];    %vymazani nulovych hodnot z tabulky   
           end
           
           if(A4{i} == 1)
              nm=[nm;ndata(i,:)];           
             % nm(isfinite(nm(:, 1)), :)  %vymazani hodnot NaN infinity
              nm(~any(nm,2),:)=[];    %vymazani nulovych hodnot z tabulky   
           end
end

   if isempty(kl)
       disp('Prazdny label: ')
       disp(lab{c})       
   else
xlswrite('P_zena.xls', kl,lab{c});
   end
   
   if isempty(lk)
       disp('Prazdny label: ')
       disp(lab{c})
   else
xlswrite('P_muz.xls', lk,lab{c});
   end
   
   if isempty(mn)
       disp('Prazdny label: ')
       disp(lab{c})    
   else
xlswrite('K_zena.xls', mn,lab{c});
   end
  
   if isempty(nm)
       disp('Prazdny label: ')
       disp(lab{c})      
   else
xlswrite('K_muz.xls', nm,lab{c});
   end
   
   end
  
%--------------------------------------------------------------------------
xls= {'P_zena.xls','P_muz.xls','K_zena.xls','K_muz.xls'};
B = length(xls);
for b=1:B

excelFileName = xls{b};
excelFilePath = pwd; % Current working directory.
sheetName = 'List'; % EN: Sheet, DE: Tabelle, etc. (Lang. dependent)

% Open Excel file.
objExcel = actxserver('Excel.Application');
objExcel.Workbooks.Open(fullfile(excelFilePath, excelFileName)); % Full path is necessary!

% Delete sheets.
try
% Throws an error if the sheets do not exist.
objExcel.ActiveWorkbook.Worksheets.Item([sheetName '1']).Delete;
objExcel.ActiveWorkbook.Worksheets.Item([sheetName '2']).Delete;
objExcel.ActiveWorkbook.Worksheets.Item([sheetName '3']).Delete;
catch
; % Do nothing.
end

% Save, close and clean up.
objExcel.ActiveWorkbook.Save;
objExcel.ActiveWorkbook.Close;
objExcel.Quit;
objExcel.delete;

end

