function varargout = bakalarska_prace(varargin)
%%%%Veverka Vojtěch,2015
% BAKALARSKA_PRACE MATLAB code for bakalarska_prace.fig
%      BAKALARSKA_PRACE, by itself, creates a new BAKALARSKA_PRACE or raises the existing
%      singleton*.
%
%      H = BAKALARSKA_PRACE returns the handle to a new BAKALARSKA_PRACE or the handle to
%      the existing singleton*.
%
%      BAKALARSKA_PRACE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in BAKALARSKA_PRACE.M with the given input arguments.
%
%      BAKALARSKA_PRACE('Property','Value',...) creates a new BAKALARSKA_PRACE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before bakalarska_prace_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to bakalarska_prace_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help bakalarska_prace

% Last Modified by GUIDE v2.5 15-May-2015 09:44:08

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @bakalarska_prace_OpeningFcn, ...
                   'gui_OutputFcn',  @bakalarska_prace_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before bakalarska_prace is made visible.
function bakalarska_prace_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to bakalarska_prace (see VARARGIN)

% Choose default command line output for bakalarska_prace
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes bakalarska_prace wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global svod pocet leads popisy referencni
svod=2; %defaultní nastavení svodu II
cesta=uigetdir; %výběr složky se signály
set(handles.edit1,'String', cesta);
a=dir(cesta); %vytvoření struktury s daty

folder_name = regexp(cesta, '\', 'split');     % proměnná folder_name je buňkové pole, ve kterém je uložena cesta k souboru rozdělená do buněk pomocí lomítek
folder_name = folder_name{end}; 
pozice_signalu = [];

  for i = 1:length(a)   % cyklus pro kontrolu signálů
            
            casti = regexp(a(i).name, {'\.','_'}, 'split');     % rozdělení každého názvu signálu ve skruktuře tečkou (pouze . značí jakýkoliv znak, pro tečku je potřeba zadat \.) a podtržítkem do buňkového pole
                    % jde o kontrolu přípon souborů (zda se jedná o soubory .mat);(v první buňce proměnné je tedy název rozdělen tečkou, vznikne např. buňka MO1_002_12 a buňka mat)
                    % podtržítko dělí společnou část názvu 
        
            if strcmp(casti{1}{end}, 'mat')  % funkce pro porovnání přípony (v případě signálů obsahuje mat) s řetězcem mat
                    % v případě, že jde o soubor mat, jeho pozice ve
                    % struktuře soubory se uloží do proměnné pozice_signalu
            
                    pozice_signalu(end+1)=i;
              
            end
        end
 pocet_signalu = length(pozice_signalu);     % zjištění počtu signálů
        
       signaly = cell(1, pocet_signalu); % nadefinování proměnné pro uložení signálů do buňkového pole s jedním řádkem a tolika sloupci, kolik je ve složce signálů
        nazvy = cell(1, pocet_signalu);  % názvy načtených signálů
      for i = 1:pocet_signalu
        nazvy{i} = a(pozice_signalu(i)).name(1:end);  
      end
                            
leads=cesta(end-1:end);  %zobrazení výběru svodu, podle toho kolika svodový záznam byl zvolen


   set(handles.listbox1,'String',nazvy);  
   pocet=length(nazvy);
   load('popisy.mat');
if leads== '12'
   popisy=popisy(:,2);
else
    popisy=popisy(:,1);
end

load('poziceQRSvCSEv2.mat');
referencni=poziceQRSvCSEv2;
NQRSc=1462;
set(handles.edit18,'String',NQRSc);


% --- Outputs from this function are returned to the command line.
function varargout = bakalarska_prace_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1
global zaznam svod signaly signal QRSref referencni KESref real_qrs cesta detektor t pomin popisy 


index_selected = get(handles.listbox1,'Value');
pomin=index_selected;
list = get(handles.listbox1,'String');
zaznam=list{index_selected}; 
folder=get(handles.edit1,'String');
fullFileName = fullfile(folder, zaznam);
storedStructure = load(fullFileName);
signaly=storedStructure.x;
signal=signaly(svod,:);
Fvz=500;
t=0:1/Fvz:length(signal)/Fvz-1/Fvz;
axes(handles.axes1);
cla
xlabel('Čas [s]');
ylabel('Napětí [uV]');
hold on
plot(t,signal)
hold on
in=index_selected;
odlisene=size(referencni,2);
    popis=popisy{in,:};
    set(handles.text18,'String',popis);
    axes(handles.axes2);
    cla
    plot(t,signal)
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    hold on


if odlisene==1
    QRSref=referencni{in,1};
    if max(QRSref)>10
    QRSref=QRSref*0.002;
    end
    line ([QRSref ;QRSref],[ylim],'color','red')
    for i=1:length(QRSref) 
    text(QRSref(:,i),max(signal),num2str(i),'Color','r')
    end
elseif odlisene==2
    QRSref2=referencni{in,1};
    QRSref2=QRSref2*0.002;
    KESref=referencni{in,2};
    KESref=KESref*0.002;
    QRSref=[QRSref2 KESref];
    line ([QRSref2 ;QRSref2],[ylim],'color','red')
    hold on
    for i=1:length(QRSref2) 
    text(QRSref2(:,i),max(signal),num2str(i),'Color','r')
    end
    if length(KESref)>0 
    line ([KESref ;KESref],[ylim],'color','black')
    for j=1:length(KESref) 
    text(KESref(:,j),max(signal),num2str(j),'Color','black')
    end
    end
end



% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global detektor signal QRS svod signaly polohy QRSref t etime NQRS
bod=ylim;
pomtex=max(signal);
if detektor==1
[QRS etime] = QRSdetektor_global(signaly,'n');
% [QRS]=QRSdetektor_combi(signaly);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==2
    [QRS etime] = QRSdetektor_local(signal,'n');
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==3
    [QRS etime] = detektorQRS_umocneni (signal);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==4 
    [QRS etime] = detektorQRS_obalka (signal);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==5
    [QRS etime] = banka_filtru(signal);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==6
    [QRS etime]=obalka_multi(signaly);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==7
    [QRS etime]=umocneni_multi(signaly);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==8
    [QRS etime] = Detektor1( signal,0);
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==9
    [QRS etime] = DetektorV( signaly, 0 );
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
elseif detektor==10
    [QRS etime] = transformace_svodu( signaly );
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
end
pocetDET=length(QRS);
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
set(handles.edit2,'String',TP);
set(handles.edit3,'String',FP);
set(handles.edit4,'String',FN);
set(handles.edit5,'String',Pplus);
set(handles.edit6,'String',SE);
set(handles.edit7,'String',pocetDET);
%%%%%ODCHYLKY%%%%%
set(handles.edit9,'String',minodchylka);
set(handles.edit10,'String',maxodchylka);
set(handles.edit11,'String',prumernaodchylka);
set(handles.edit16,'String',err);
set(handles.edit17,'String',etime);
set(handles.edit19,'String',PI);



% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global pocet svod popisy referencni NQRSc
NQRSc=str2num(get(handles.edit18,'String'));
for i =1:pocet
    index_selected = i;
    list = get(handles.listbox1,'String');
    zaznam=list{index_selected}; 
    folder=get(handles.edit1,'String');
    fullFileName = fullfile(folder, zaznam);
    storedStructure = load(fullFileName);
    signals=storedStructure.x;
    onesignal=signals(svod,:);
if  size(referencni,2)>1
    load('poziceQRSvCSEv2.mat');
    referencni=poziceQRSvCSEv2;
end
QRSref=referencni{i,1}    
if max(QRSref)>10
    QRSref=QRSref*0.002;
end

%TEST PRVNIHO DETEKTORU    
    [QRS etime] = QRSdetektor_global(signals,'n');
    QRS=QRS*0.002;
    QRSref=QRSref;
    detQRS=length (QRS);
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    resultsdet1{i,1}=detQRS;
    resultsdet1{i,2}=TP;
    resultsdet1{i,3}=FN;
    resultsdet1{i,4}=FP;
    resultsdet1{i,5}=SE;
    resultsdet1{i,6}=Pplus;
    resultsdet1{i,7}=minodchylka;
    resultsdet1{i,8}=maxodchylka;
    resultsdet1{i,9}=prumernaodchylka;
    resultsdet1{i,10}=etime;
    resultsdet1{i,11}=PI;
    resultsdet1{i,12}=popisy{i,:};
%TEST DRUHEHO DETEKTORU      
    [QRS etime] = QRSdetektor_local(onesignal,'n');
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet2{i,1}=detQRS;
    resultsdet2{i,2}=TP;
    resultsdet2{i,3}=FN;
    resultsdet2{i,4}=FP;
    resultsdet2{i,5}=SE;
    resultsdet2{i,6}=Pplus;
    resultsdet2{i,7}=minodchylka;
    resultsdet2{i,8}=maxodchylka;
    resultsdet2{i,9}=prumernaodchylka;
    resultsdet2{i,10}=etime;
    resultsdet2{i,11}=PI;
    resultsdet2{i,12}=popisy{i,:};
%TEST TRETIHO DETEKTORU     
    [QRS etime] = detektorQRS_umocneni (onesignal);
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet3{i,1}=detQRS;
    resultsdet3{i,2}=TP;
    resultsdet3{i,3}=FN;
    resultsdet3{i,4}=FP;
    resultsdet3{i,5}=SE;
    resultsdet3{i,6}=Pplus;
    resultsdet3{i,7}=minodchylka;
    resultsdet3{i,8}=maxodchylka;
    resultsdet3{i,9}=prumernaodchylka;
    resultsdet3{i,10}=etime;
    resultsdet3{i,11}=PI;
    resultsdet3{i,12}=popisy{i,:};
%TEST CTVRTEHO DETEKTORU       
    [QRS etime] = detektorQRS_obalka (onesignal);
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet4{i,1}=detQRS;
    resultsdet4{i,2}=TP;
    resultsdet4{i,3}=FN;
    resultsdet4{i,4}=FP;
    resultsdet4{i,5}=SE;
    resultsdet4{i,6}=Pplus;
    resultsdet4{i,7}=minodchylka;
    resultsdet4{i,8}=maxodchylka;
    resultsdet4{i,9}=prumernaodchylka;
    resultsdet4{i,10}=etime;
    resultsdet4{i,11}=PI;
    resultsdet4{i,12}=popisy{i,:};
%TEST PATEHO DETEKTORU   
    [QRS etime] = banka_filtru(onesignal);
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet5{i,1}=detQRS;
    resultsdet5{i,2}=TP;
    resultsdet5{i,3}=FN;
    resultsdet5{i,4}=FP;
    resultsdet5{i,5}=SE;
    resultsdet5{i,6}=Pplus;
    resultsdet5{i,7}=minodchylka;
    resultsdet5{i,8}=maxodchylka;
    resultsdet5{i,9}=prumernaodchylka;
    resultsdet5{i,10}=etime;
    resultsdet5{i,11}=PI;
    resultsdet5{i,12}=popisy{i,:};
%TEST SESTEHO DETEKTORU   
    [QRS etime]=obalka_multi(signals);
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet6{i,1}=detQRS;
    resultsdet6{i,2}=TP;
    resultsdet6{i,3}=FN;
    resultsdet6{i,4}=FP;
    resultsdet6{i,5}=SE;
    resultsdet6{i,6}=Pplus;
    resultsdet6{i,7}=minodchylka;
    resultsdet6{i,8}=maxodchylka;
    resultsdet6{i,9}=prumernaodchylka;
    resultsdet6{i,10}=etime;
    resultsdet6{i,11}=PI;
    resultsdet6{i,12}=popisy{i,:};
%TEST SEDMEHO DETEKTORU   
    [QRS etime]=umocneni_multi(signals);
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet7{i,1}=detQRS;
    resultsdet7{i,2}=TP;
    resultsdet7{i,3}=FN;
    resultsdet7{i,4}=FP;
    resultsdet7{i,5}=SE;
    resultsdet7{i,6}=Pplus;
    resultsdet7{i,7}=minodchylka;
    resultsdet7{i,8}=maxodchylka;
    resultsdet7{i,9}=prumernaodchylka;
    resultsdet7{i,10}=etime;
    resultsdet7{i,11}=PI;
    resultsdet7{i,12}=popisy{i,:};
%TEST OSMEHO DETEKTORU   
    [QRS etime] = Detektor1( onesignal,0);
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet8{i,1}=detQRS;
    resultsdet8{i,2}=TP;
    resultsdet8{i,3}=FN;
    resultsdet8{i,4}=FP;
    resultsdet8{i,5}=SE;
    resultsdet8{i,6}=Pplus;
    resultsdet8{i,7}=minodchylka;
    resultsdet8{i,8}=maxodchylka;
    resultsdet8{i,9}=prumernaodchylka;
    resultsdet8{i,10}=etime;
    resultsdet8{i,11}=PI;
    resultsdet8{i,12}=popisy{i,:};
%TEST DEVATEHO DETEKTORU   
    [QRS etime] = DetektorV( signals, 0 );
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet9{i,1}=detQRS;
    resultsdet9{i,2}=TP;
    resultsdet9{i,3}=FN;
    resultsdet9{i,4}=FP;
    resultsdet9{i,5}=SE;
    resultsdet9{i,6}=Pplus;
    resultsdet9{i,7}=minodchylka;
    resultsdet9{i,8}=maxodchylka;
    resultsdet9{i,9}=prumernaodchylka; 
    resultsdet9{i,10}=etime;
    resultsdet9{i,11}=PI;
    resultsdet9{i,12}=popisy{i,:};
%TEST DESATEHO DETEKTORU
[QRS etime]= transformace_svodu(signals)
QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet10{i,1}=detQRS;
    resultsdet10{i,2}=TP;
    resultsdet10{i,3}=FN;
    resultsdet10{i,4}=FP;
    resultsdet10{i,5}=SE;
    resultsdet10{i,6}=Pplus;
    resultsdet10{i,7}=minodchylka;
    resultsdet10{i,8}=maxodchylka;
    resultsdet10{i,9}=prumernaodchylka; 
    resultsdet10{i,10}=etime;
    resultsdet10{i,11}=PI;
    resultsdet10{i,12}=popisy{i,:};
end
%VÝPOČET PRŮMĚRŮ a SOUČTŮ
  %Součet všech detekovaných komplexů
    alldet1=sum(cell2mat(resultsdet1(:,1)));
    alldet2=sum(cell2mat(resultsdet2(:,1)));
    alldet3=sum(cell2mat(resultsdet3(:,1)));
    alldet4=sum(cell2mat(resultsdet4(:,1)));
    alldet5=sum(cell2mat(resultsdet5(:,1)));
    alldet6=sum(cell2mat(resultsdet6(:,1)));
    alldet7=sum(cell2mat(resultsdet7(:,1)));
    alldet8=sum(cell2mat(resultsdet8(:,1)));
    alldet9=sum(cell2mat(resultsdet9(:,1)));
    alldet10=sum(cell2mat(resultsdet10(:,1)));

    resultsdet1{end+1,1}=alldet1;
    resultsdet2{end+1,1}=alldet2;
    resultsdet3{end+1,1}=alldet3;
    resultsdet4{end+1,1}=alldet4;
    resultsdet5{end+1,1}=alldet5;
    resultsdet6{end+1,1}=alldet6;
    resultsdet7{end+1,1}=alldet7;
    resultsdet8{end+1,1}=alldet8;
    resultsdet9{end+1,1}=alldet9;
    resultsdet10{end+1,1}=alldet10;
  %Součet TP
    TP1=sum(cell2mat(resultsdet1(:,2)));
    TP2=sum(cell2mat(resultsdet2(:,2)));
    TP3=sum(cell2mat(resultsdet3(:,2)));
    TP4=sum(cell2mat(resultsdet4(:,2)));
    TP5=sum(cell2mat(resultsdet5(:,2)));
    TP6=sum(cell2mat(resultsdet6(:,2)));
    TP7=sum(cell2mat(resultsdet7(:,2)));
    TP8=sum(cell2mat(resultsdet8(:,2)));
    TP9=sum(cell2mat(resultsdet9(:,2)));
    TP10=sum(cell2mat(resultsdet10(:,2)));
    resultsdet1{end,2}=TP1;
    resultsdet2{end,2}=TP2;
    resultsdet3{end,2}=TP3;
    resultsdet4{end,2}=TP4;
    resultsdet5{end,2}=TP5;
    resultsdet6{end,2}=TP6;
    resultsdet7{end,2}=TP7;
    resultsdet8{end,2}=TP8;
    resultsdet9{end,2}=TP9;
    resultsdet10{end,2}=TP10;
  %Součet FN
    FN1=sum(cell2mat(resultsdet1(:,3)));
    FN2=sum(cell2mat(resultsdet2(:,3)));
    FN3=sum(cell2mat(resultsdet3(:,3)));
    FN4=sum(cell2mat(resultsdet4(:,3)));
    FN5=sum(cell2mat(resultsdet5(:,3)));
    FN6=sum(cell2mat(resultsdet6(:,3)));
    FN7=sum(cell2mat(resultsdet7(:,3)));
    FN8=sum(cell2mat(resultsdet8(:,3)));
    FN9=sum(cell2mat(resultsdet9(:,3)));
    FN10=sum(cell2mat(resultsdet10(:,3)));
    resultsdet1{end,3}=FN1;
    resultsdet2{end,3}=FN2;
    resultsdet3{end,3}=FN3;
    resultsdet4{end,3}=FN4;
    resultsdet5{end,3}=FN5;
    resultsdet6{end,3}=FN6;
    resultsdet7{end,3}=FN7;
    resultsdet8{end,3}=FN8;
    resultsdet9{end,3}=FN9;
    resultsdet10{end,3}=FN10;
  %Součet FP
    FP1=sum(cell2mat(resultsdet1(:,4)));
    FP2=sum(cell2mat(resultsdet2(:,4)));
    FP3=sum(cell2mat(resultsdet3(:,4)));
    FP4=sum(cell2mat(resultsdet4(:,4)));
    FP5=sum(cell2mat(resultsdet5(:,4)));
    FP6=sum(cell2mat(resultsdet6(:,4)));
    FP7=sum(cell2mat(resultsdet7(:,4)));
    FP8=sum(cell2mat(resultsdet8(:,4)));
    FP9=sum(cell2mat(resultsdet9(:,4)));
    FP10=sum(cell2mat(resultsdet10(:,4)));
    resultsdet1{end,4}=FP1;
    resultsdet2{end,4}=FP2;
    resultsdet3{end,4}=FP3;
    resultsdet4{end,4}=FP4;
    resultsdet5{end,4}=FP5;
    resultsdet6{end,4}=FP6;
    resultsdet7{end,4}=FP7;
    resultsdet8{end,4}=FP8;
    resultsdet9{end,4}=FP9;
    resultsdet10{end,4}=FP10;
  %Průměrná senzitivita
    SE1=TP1/(TP1+FN1);
    SE2=TP2/(TP2+FN2);
    SE3=TP3/(TP3+FN3);
    SE4=TP4/(TP4+FN4);
    SE5=TP5/(TP5+FN5);
    SE6=TP6/(TP6+FN6);
    SE7=TP7/(TP7+FN7);
    SE8=TP8/(TP8+FN8);
    SE9=TP9/(TP9+FN9);
    SE10=TP10/(TP10+FN10);
    resultsdet1{end,5}=SE1;
    resultsdet2{end,5}=SE2;
    resultsdet3{end,5}=SE3;
    resultsdet4{end,5}=SE4;
    resultsdet5{end,5}=SE5;
    resultsdet6{end,5}=SE6;
    resultsdet7{end,5}=SE7;
    resultsdet8{end,5}=SE8;
    resultsdet9{end,5}=SE9;
    resultsdet10{end,5}=SE10;
  %Průměrná pozitivní prediktivita
    pplus1=TP1/(TP1+FP1);
    pplus2=TP2/(TP2+FP2);
    pplus3=TP3/(TP3+FP3);
    pplus4=TP4/(TP4+FP4);
    pplus5=TP5/(TP5+FP5);
    pplus6=TP6/(TP6+FP6);
    pplus7=TP7/(TP7+FP7);
    pplus8=TP8/(TP8+FP8);
    pplus9=TP9/(TP9+FP9);
    pplus10=TP10/(TP10+FP10);
    resultsdet1{end,6}=pplus1;
    resultsdet2{end,6}=pplus2;
    resultsdet3{end,6}=pplus3;
    resultsdet4{end,6}=pplus4;
    resultsdet5{end,6}=pplus5;
    resultsdet6{end,6}=pplus6;
    resultsdet7{end,6}=pplus7;
    resultsdet8{end,6}=pplus8;
    resultsdet9{end,6}=pplus9;  
    resultsdet10{end,6}=pplus10; 
    
    etime1=mean(cell2mat(resultsdet1(:,10)));
    etime2=mean(cell2mat(resultsdet2(:,10)));
    etime3=mean(cell2mat(resultsdet3(:,10)));
    etime4=mean(cell2mat(resultsdet4(:,10)));
    etime5=mean(cell2mat(resultsdet5(:,10)));
    etime6=mean(cell2mat(resultsdet6(:,10)));
    etime7=mean(cell2mat(resultsdet7(:,10)));
    etime8=mean(cell2mat(resultsdet8(:,10)));
    etime9=mean(cell2mat(resultsdet9(:,10)));
    etime10=mean(cell2mat(resultsdet10(:,10)));
    resultsdet1{end,10}=etime1;
    resultsdet2{end,10}=etime2;
    resultsdet3{end,10}=etime3;
    resultsdet4{end,10}=etime4;
    resultsdet5{end,10}=etime5;
    resultsdet6{end,10}=etime6;
    resultsdet7{end,10}=etime7;
    resultsdet8{end,10}=etime8;
    resultsdet9{end,10}=etime9;  
    resultsdet10{end,10}=etime10; 
%Průměrný index výkonosti
    PI1=((NQRSc-(FN1+FP1))/NQRSc);
    PI2=((NQRSc-(FN2+FP2))/NQRSc);
    PI3=((NQRSc-(FN3+FP3))/NQRSc);
    PI4=((NQRSc-(FN4+FP4))/NQRSc);
    PI5=((NQRSc-(FN5+FP5))/NQRSc);
    PI6=((NQRSc-(FN6+FP6))/NQRSc);
    PI7=((NQRSc-(FN7+FP7))/NQRSc);
    PI8=((NQRSc-(FN8+FP8))/NQRSc);
    PI9=((NQRSc-(FN9+FP9))/NQRSc);
    PI10=((NQRSc-(FN10+FP10))/NQRSc);
    resultsdet1{end,11}=PI1;
    resultsdet2{end,11}=PI2;
    resultsdet3{end,11}=PI3;
    resultsdet4{end,11}=PI4;
    resultsdet5{end,11}=PI5;
    resultsdet6{end,11}=PI6;
    resultsdet7{end,11}=PI7;
    resultsdet8{end,11}=PI8;
    resultsdet9{end,11}=PI9;
    resultsdet10{end,11}=PI10;
%EXPORT VÝSLEDKŮ DO SOUBORU XLS (EXCEL) 
A={'N', 'TP','FN','FP','Senzitivita','Pozitivní prediktivita','Minimální odchylka','Maximální odchylka','Průměrná odchylka','Čas detekce [s]','Index výkonnosti []','Stručný popis'};
 filename = 'results_of_analysis.xlsx';
xlswrite(filename,A,'Detektor_global','A1')
xlswrite(filename,resultsdet1,'Detektor_global','A2')
xlswrite(filename,A,'Detektor_local','A1')
xlswrite(filename,resultsdet2,'Detektor_local','A2')
xlswrite(filename,A,'Detektor_umocneni','A1')
xlswrite(filename,resultsdet3,'Detektor_umocneni','A2')
xlswrite(filename,A,'Detektor_obalka','A1')
xlswrite(filename,resultsdet4,'Detektor_obalka','A2')
xlswrite(filename,A,'Detektor_banka','A1')
xlswrite(filename,resultsdet5,'Detektor_banka','A2')
xlswrite(filename,A,'Detektor_obal_mul','A1')
xlswrite(filename,resultsdet6,'Detektor_obal_mul','A2')
xlswrite(filename,A,'Detektor_um_mul','A1')
xlswrite(filename,resultsdet7,'Detektor_um_mul','A2')
xlswrite(filename,A,'Detektor_mehta','A1')
xlswrite(filename,resultsdet8,'Detektor_mehta','A2')
xlswrite(filename,A,'Detektor_mehta_mul','A1')
xlswrite(filename,resultsdet9,'Detektor_mehta_mul','A2')
xlswrite(filename,A,'Detektor_trans_svod','A1')
xlswrite(filename,resultsdet10,'Detektor_trans_svod','A2')


% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global svod
   sv1=get(handles.radiobutton16,'Value');
   sv2=get(handles.radiobutton17,'Value');
   sv3=get(handles.radiobutton18,'Value');
   if sv1==1
       svod=1;
   elseif sv2==1
       svod=2;
   elseif sv3==1
       svod=3; 
   end
listbox1_Callback(hObject, eventdata, handles)


% --- Executes when selected object is changed in uipanel2.
function uipanel2_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel2 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global svod
   sv1=get(handles.radiobutton4,'Value');
   sv2=get(handles.radiobutton5,'Value');
   sv3=get(handles.radiobutton6,'Value');
   sv4=get(handles.radiobutton7,'Value');
   sv5=get(handles.radiobutton8,'Value');
   sv6=get(handles.radiobutton9,'Value');
   sv7=get(handles.radiobutton10,'Value');
   sv8=get(handles.radiobutton11,'Value');
   sv9=get(handles.radiobutton12,'Value');
   sv10=get(handles.radiobutton13,'Value');
   sv11=get(handles.radiobutton14,'Value');
   sv12=get(handles.radiobutton15,'Value');
   if sv1==1
       svod=1;
   elseif sv2==1
       svod=2;
   elseif sv3==1
       svod=3;
   elseif sv4==1
       svod=4;
   elseif sv5==1
       svod=5;
   elseif sv6==1
       svod=6;
   elseif sv7==1
       svod=7;
   elseif sv8==1
       svod=8;
   elseif sv9==1
       svod=9;
   elseif sv10==1
       svod=10;
   elseif sv11==1
       svod=11;
   elseif sv12==1
       svod=12;
   end
   listbox1_Callback(hObject, eventdata, handles)



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes when selected object is changed in uipanel3.
function uipanel3_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel3 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global detektor leads
   det1=get(handles.radiobutton19,'Value');
   det2=get(handles.radiobutton20,'Value');
   det3=get(handles.radiobutton21,'Value');
   det4=get(handles.radiobutton22,'Value');
   det5=get(handles.radiobutton23,'Value');
   det6=get(handles.radiobutton24,'Value');
   det7=get(handles.radiobutton25,'Value');
   det8=get(handles.radiobutton26,'Value');
   det9=get(handles.radiobutton27,'Value');
   det10=get(handles.radiobutton28,'Value');
   if det1==1
       detektor=1;
       set(handles.uipanel2,'Visible','off');
       set(handles.uipanel1,'Visible','off');
   elseif det2==1
       detektor=2;
if leads== '12'
    set(handles.uipanel2,'Visible','on');
else
    set(handles.uipanel1,'Visible','on');
end
   elseif det3==1
       detektor=3;
if leads== '12'
    set(handles.uipanel2,'Visible','on');
else
    set(handles.uipanel1,'Visible','on');
end
   elseif det4==1
       detektor=4;
if leads== '12'
    set(handles.uipanel2,'Visible','on');
else
    set(handles.uipanel1,'Visible','on');
end
   elseif det5==1
       detektor=5;
if leads== '12'
    set(handles.uipanel2,'Visible','on');
else
    set(handles.uipanel1,'Visible','on');
end
   elseif det6==1
       detektor=6;
       set(handles.uipanel2,'Visible','off');
       set(handles.uipanel1,'Visible','off');
   elseif det7==1
       detektor=7;
       set(handles.uipanel2,'Visible','off');
       set(handles.uipanel1,'Visible','off');
   elseif det8==1
       detektor=8;
if leads== '12'
    set(handles.uipanel2,'Visible','on');
else
    set(handles.uipanel1,'Visible','on');
end
   elseif det9==1
       detektor=9;
       set(handles.uipanel2,'Visible','off');
       set(handles.uipanel1,'Visible','off');
   elseif det10==1
       detektor=10;
       set(handles.uipanel2,'Visible','off');
       set(handles.uipanel1,'Visible','off');
   end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global QRSref signal pomin t QRSman QRSmanref
axes(handles.axes2);
cla
plot(t,signal)
hold on
[x,y] = ginput;
x=x(:)';
QRSref=[x];
QRSmanref{pomin,1}=[QRSref];
save('QRSmanref.mat', 'QRSmanref')
axes(handles.axes2);
bod=ylim;
line ([x ;x],[ylim],'color','red')



function edit13_Callback(hObject, eventdata, handles)
% hObject    handle to edit13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit13 as text
%        str2double(get(hObject,'String')) returns contents of edit13 as a double


% --- Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit14_Callback(hObject, eventdata, handles)
% hObject    handle to edit14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit14 as text
%        str2double(get(hObject,'String')) returns contents of edit14 as a double


% --- Executes during object creation, after setting all properties.
function edit14_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global pocet svod popisy NQRSc
NQRSc=str2num(get(handles.edit18,'String'));
pocetsignalu=0;
load('poziceQRSvCSEv2.mat')
conwri=0;
A={'N', 'TP','FN','FP','Senzitivita','Pozitivní prediktivita','Minimální odchylka','Maximální odchylka','Průměrná odchylka','Čas detekce','Index výkonosti','Stručný popis'};
 filename = 'results_user_choose.xlsx';
%KONTROLA VYBRANYCH DETEKTORU
chd1=get(handles.checkbox1,'Value');
chd2=get(handles.checkbox2,'Value');
chd3=get(handles.checkbox3,'Value');
chd4=get(handles.checkbox4,'Value');
chd5=get(handles.checkbox5,'Value');
chd6=get(handles.checkbox6,'Value');
chd7=get(handles.checkbox7,'Value');
chd8=get(handles.checkbox8,'Value');
chd9=get(handles.checkbox9,'Value');
chd10=get(handles.checkbox10,'Value');
for i =1:pocet
    index_selected = i;
    list = get(handles.listbox1,'String');
    zaznam=list{index_selected}; 
    folder=get(handles.edit1,'String');
    fullFileName = fullfile(folder, zaznam);
    storedStructure = load(fullFileName);
    signals=storedStructure.x;
    onesignal=signals(svod,:);
    QRSref=poziceQRSvCSEv2{i,:};
    QRSref=QRSref*0.002;
if chd1==1
[QRS etime] = QRSdetektor_global(signals,'n');
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet1{i,1}=detQRS;
    resultsdet1{i,2}=TP;
    resultsdet1{i,3}=FN;
    resultsdet1{i,4}=FP;
    resultsdet1{i,5}=SE;
    resultsdet1{i,6}=Pplus;
    resultsdet1{i,7}=minodchylka;
    resultsdet1{i,8}=maxodchylka;
    resultsdet1{i,9}=prumernaodchylka;
    resultsdet1{i,10}=etime;
    resultsdet1{i,11}=PI;
    resultsdet1{i,12}=popisy{i,:};
end
if chd2==1
    QRS = QRSdetektor_local(onesignal,'n');
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet2{i,1}=detQRS;
    resultsdet2{i,2}=TP;
    resultsdet2{i,3}=FN;
    resultsdet2{i,4}=FP;
    resultsdet2{i,5}=SE;
    resultsdet2{i,6}=Pplus;
    resultsdet2{i,7}=minodchylka;
    resultsdet2{i,8}=maxodchylka;
    resultsdet2{i,9}=prumernaodchylka;
    resultsdet2{i,10}=etime;
    resultsdet2{i,11}=PI;
    resultsdet2{i,12}=popisy{i,:};
end
if chd3==1
    [QRS etime] = detektorQRS_umocneni (onesignal);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet3{i,1}=detQRS;
    resultsdet3{i,2}=TP;
    resultsdet3{i,3}=FN;
    resultsdet3{i,4}=FP;
    resultsdet3{i,5}=SE;
    resultsdet3{i,6}=Pplus;
    resultsdet3{i,7}=minodchylka;
    resultsdet3{i,8}=maxodchylka;
    resultsdet3{i,9}=prumernaodchylka;
    resultsdet3{i,10}=etime;
    resultsdet3{i,11}=PI;
    resultsdet3{i,12}=popisy{i,:};
end
if chd4==1
    [QRS etime] = detektorQRS_obalka (onesignal);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet4{i,1}=detQRS;
    resultsdet4{i,2}=TP;
    resultsdet4{i,3}=FN;
    resultsdet4{i,4}=FP;
    resultsdet4{i,5}=SE;
    resultsdet4{i,6}=Pplus;
    resultsdet4{i,7}=minodchylka;
    resultsdet4{i,8}=maxodchylka;
    resultsdet4{i,9}=prumernaodchylka;
    resultsdet4{i,10}=etime;
    resultsdet4{i,11}=PI;
    resultsdet4{i,12}=popisy{i,:};
end
if chd5==1
    [QRS etime] = banka_filtru(onesignal);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet5{i,1}=detQRS;
    resultsdet5{i,2}=TP;
    resultsdet5{i,3}=FN;
    resultsdet5{i,4}=FP;
    resultsdet5{i,5}=SE;
    resultsdet5{i,6}=Pplus;
    resultsdet5{i,7}=minodchylka;
    resultsdet5{i,8}=maxodchylka;
    resultsdet5{i,9}=prumernaodchylka;
    resultsdet5{i,10}=etime;
    resultsdet5{i,11}=PI;
    resultsdet5{i,12}=popisy{i,:};
end
if chd6==1
   [QRS etime]=obalka_multi(signals);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet6{i,1}=detQRS;
    resultsdet6{i,2}=TP;
    resultsdet6{i,3}=FN;
    resultsdet6{i,4}=FP;
    resultsdet6{i,5}=SE;
    resultsdet6{i,6}=Pplus;
    resultsdet6{i,7}=minodchylka;
    resultsdet6{i,8}=maxodchylka;
    resultsdet6{i,9}=prumernaodchylka;
    resultsdet6{i,10}=etime;
    resultsdet6{i,11}=PI;
    resultsdet6{i,12}=popisy{i,:};
end
if chd7==1
   [QRS etime]=umocneni_multi(signals);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet7{i,1}=detQRS;
    resultsdet7{i,2}=TP;
    resultsdet7{i,3}=FN;
    resultsdet7{i,4}=FP;
    resultsdet7{i,5}=SE;
    resultsdet7{i,6}=Pplus;
    resultsdet7{i,7}=minodchylka;
    resultsdet7{i,8}=maxodchylka;
    resultsdet7{i,9}=prumernaodchylka;
    resultsdet7{i,10}=etime;
    resultsdet7{i,11}=PI;
    resultsdet7{i,12}=popisy{i,:};
end
if chd8==1
    [QRS etime] = Detektor1( onesignal,0);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet8{i,1}=detQRS;
    resultsdet8{i,2}=TP;
    resultsdet8{i,3}=FN;
    resultsdet8{i,4}=FP;
    resultsdet8{i,5}=SE;
    resultsdet8{i,6}=Pplus;
    resultsdet8{i,7}=minodchylka;
    resultsdet8{i,8}=maxodchylka;
    resultsdet8{i,9}=prumernaodchylka;
    resultsdet8{i,10}=etime;
    resultsdet8{i,11}=PI;
    resultsdet8{i,12}=popisy{i,:};
end
if chd9==1
    [QRS etime] = DetektorV( signals, 0 );
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet9{i,1}=detQRS;
    resultsdet9{i,2}=TP;
    resultsdet9{i,3}=FN;
    resultsdet9{i,4}=FP;
    resultsdet9{i,5}=SE;
    resultsdet9{i,6}=Pplus;
    resultsdet9{i,7}=minodchylka;
    resultsdet9{i,8}=maxodchylka;
    resultsdet9{i,9}=prumernaodchylka; 
    resultsdet9{i,10}=etime;
    resultsdet9{i,11}=PI;
    resultsdet9{i,12}=popisy{i,:};
end
if chd10==1
    [QRS etime]= transformace_svodu(signals);
    QRS=QRS*0.002;

[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdet10{i,1}=detQRS;
    resultsdet10{i,2}=TP;
    resultsdet10{i,3}=FN;
    resultsdet10{i,4}=FP;
    resultsdet10{i,5}=SE;
    resultsdet10{i,6}=Pplus;
    resultsdet10{i,7}=minodchylka;
    resultsdet10{i,8}=maxodchylka;
    resultsdet10{i,9}=prumernaodchylka; 
    resultsdet10{i,10}=etime;
    resultsdet10{i,11}=PI;
    resultsdet10{i,12}=popisy{i,:};
end
end
if exist('resultsdet1')==1
alldet1=sum(cell2mat(resultsdet1(:,1)));
resultsdet1{end+1,1}=alldet1;
TP1=sum(cell2mat(resultsdet1(:,2)));
resultsdet1{end,2}=TP1;
FN1=sum(cell2mat(resultsdet1(:,3)));
resultsdet1{end,3}=FN1;
FP1=sum(cell2mat(resultsdet1(:,4)));
resultsdet1{end,4}=FP1;
SE1=TP1/(TP1+FN1);
resultsdet1{end,5}=SE1;
pplus1=TP1/(TP1+FP1);
resultsdet1{end,6}=pplus1;
PI1=((NQRSc-(FN1+FP1))/NQRSc);
resultsdet1{end,11}=PI1;
xlswrite(filename,A,'Detektor_global','A1')
xlswrite(filename,resultsdet1,'Detektor_global','A2')
end
if exist('resultsdet2')==1
alldet2=sum(cell2mat(resultsdet2(:,1)));
resultsdet2{end+1,1}=alldet2;
TP2=sum(cell2mat(resultsdet2(:,2)));
resultsdet2{end,2}=TP2;
FN2=sum(cell2mat(resultsdet2(:,3)));
resultsdet2{end,3}=FN2;
FP2=sum(cell2mat(resultsdet2(:,4)));
resultsdet2{end,4}=FP2;
SE2=TP2/(TP2+FN2);
resultsdet2{end,5}=SE2;
pplus2=TP2/(TP2+FP2);
resultsdet2{end,6}=pplus2;
PI2=((NQRSc-(FN2+FP2))/NQRSc);
resultsdet2{end,11}=PI2;
xlswrite(filename,A,'Detektor_local','A1')
xlswrite(filename,resultsdet2,'Detektor_local','A2')
end
if exist('resultsdet3')==1
alldet3=sum(cell2mat(resultsdet3(:,1)));
resultsdet3{end+1,1}=alldet3;
TP3=sum(cell2mat(resultsdet3(:,2)));
resultsdet3{end,2}=TP3;
FN3=sum(cell2mat(resultsdet3(:,3)));
resultsdet3{end,3}=FN3;
FP3=sum(cell2mat(resultsdet3(:,4)));
resultsdet3{end,4}=FP3;
SE3=TP3/(TP3+FN3);
resultsdet3{end,5}=SE3;
pplus3=TP3/(TP3+FP3);
resultsdet3{end,6}=pplus3;
PI3=((NQRSc-(FN3+FP3))/NQRSc);
resultsdet3{end,11}=PI3;
xlswrite(filename,A,'Detektor_umocneni','A1')
xlswrite(filename,resultsdet3,'Detektor_umocneni','A2')
end
if exist('resultsdet4')==1
alldet4=sum(cell2mat(resultsdet4(:,1)));
resultsdet4{end+1,1}=alldet4;
TP4=sum(cell2mat(resultsdet4(:,2)));
resultsdet4{end,2}=TP4;
FN4=sum(cell2mat(resultsdet4(:,3)));
resultsdet4{end,3}=FN4;
FP4=sum(cell2mat(resultsdet4(:,4)));
resultsdet4{end,4}=FP4;
SE4=TP4/(TP4+FN4);
resultsdet4{end,5}=SE4;
pplus4=TP4/(TP4+FP4);
resultsdet4{end,6}=pplus4;
PI4=((NQRSc-(FN4+FP4))/NQRSc);
resultsdet4{end,11}=PI4;
xlswrite(filename,A,'Detektor_obal','A1')
xlswrite(filename,resultsdet4,'Detektor_obal','A2')
end
if exist('resultsdet5')==1
alldet5=sum(cell2mat(resultsdet5(:,1)));
resultsdet5{end+1,1}=alldet5;
TP5=sum(cell2mat(resultsdet5(:,2)));
resultsdet5{end,2}=TP5;
FN5=sum(cell2mat(resultsdet5(:,3)));
resultsdet5{end,3}=FN5;
FP5=sum(cell2mat(resultsdet5(:,4)));
resultsdet5{end,4}=FP5;
SE5=TP5/(TP5+FN5);
resultsdet5{end,5}=SE5;
pplus5=TP5/(TP5+FP5);
resultsdet5{end,6}=pplus5;
PI5=((NQRSc-(FN5+FP5))/NQRSc);
resultsdet5{end,11}=PI5;
xlswrite(filename,A,'Detektor_banka','A1')
xlswrite(filename,resultsdet5,'Detektor_banka','A2')
end
if exist('resultsdet6')==1
alldet6=sum(cell2mat(resultsdet6(:,1)));
resultsdet6{end+1,1}=alldet6;
TP6=sum(cell2mat(resultsdet6(:,2)));
resultsdet6{end,2}=TP6;
FN6=sum(cell2mat(resultsdet6(:,3)));
resultsdet6{end,3}=FN6;
FP6=sum(cell2mat(resultsdet6(:,4)));
resultsdet6{end,4}=FP6;
SE6=TP6/(TP6+FN6);
resultsdet6{end,5}=SE6;
pplus6=TP6/(TP6+FP6);
resultsdet6{end,6}=pplus6;
PI6=((NQRSc-(FN6+FP6))/NQRSc);
resultsdet6{end,11}=PI6;
xlswrite(filename,A,'Detektor_obal_multi','A1')
xlswrite(filename,resultsdet6,'Detektor_obal_multi','A2')
end
if exist('resultsdet7')==1
alldet7=sum(cell2mat(resultsdet7(:,1)));
resultsdet7{end+1,1}=alldet7;
TP7=sum(cell2mat(resultsdet7(:,2)));
resultsdet7{end,2}=TP7;
FN7=sum(cell2mat(resultsdet7(:,3)));
resultsdet7{end,3}=FN7;
FP7=sum(cell2mat(resultsdet7(:,4)));
resultsdet7{end,4}=FP7;
SE7=TP7/(TP7+FN7);
resultsdet7{end,5}=SE7;
pplus7=TP7/(TP7+FP7);
resultsdet7{end,6}=pplus7;
PI7=((NQRSc-(FN7+FP7))/NQRSc);
resultsdet7{end,11}=PI7;
xlswrite(filename,A,'Detektor_umocneni_multi','A1')
xlswrite(filename,resultsdet7,'Detektor_umocneni_multi','A2')
end
if exist('resultsdet8')==1
alldet8=sum(cell2mat(resultsdet8(:,1)));
resultsdet8{end+1,1}=alldet8;
TP8=sum(cell2mat(resultsdet8(:,2)));
resultsdet8{end,2}=TP8;
FN8=sum(cell2mat(resultsdet8(:,3)));
resultsdet8{end,3}=FN8;
FP8=sum(cell2mat(resultsdet8(:,4)));
resultsdet8{end,4}=FP8;
SE8=TP8/(TP8+FN8);
resultsdet8{end,5}=SE8;
pplus8=TP8/(TP8+FP8);
resultsdet8{end,6}=pplus8;
PI8=((NQRSc-(FN8+FP8))/NQRSc);
resultsdet8{end,11}=PI8;
xlswrite(filename,A,'Detektor_mehta','A1')
xlswrite(filename,resultsdet8,'Detektor_mehta','A2')
end
if exist('resultsdet9')==1
alldet9=sum(cell2mat(resultsdet9(:,1)));
resultsdet9{end+1,1}=alldet9;
TP9=sum(cell2mat(resultsdet9(:,2)));
resultsdet9{end,2}=TP9;
FN9=sum(cell2mat(resultsdet9(:,3)));
resultsdet9{end,3}=FN9;
FP9=sum(cell2mat(resultsdet9(:,4)));
resultsdet9{end,4}=FP9;
SE9=TP9/(TP9+FN9);
resultsdet9{end,5}=SE9;
pplus9=TP9/(TP9+FP9);
resultsdet9{end,6}=pplus9;
PI9=((NQRSc-(FN9+FP9))/NQRSc);
resultsdet9{end,11}=PI9;
xlswrite(filename,A,'Detektor_mehta_multi','A1')
xlswrite(filename,resultsdet9,'Detektor_mehta_multi','A2')
end
if exist('resultsdet10')==1
alldet10=sum(cell2mat(resultsdet10(:,1)));
resultsdet10{end+1,1}=alldet10;
TP10=sum(cell2mat(resultsdet10(:,2)));
resultsdet10{end,2}=TP10;
FN10=sum(cell2mat(resultsdet10(:,3)));
resultsdet10{end,3}=FN10;
FP10=sum(cell2mat(resultsdet10(:,4)));
resultsdet10{end,4}=FP10;
SE10=TP10/(TP10+FN10);
resultsdet10{end,5}=SE10;
pplus10=TP10/(TP10+FP10);
resultsdet10{end,6}=pplus10;
PI10=((NQRSc-(FN10+FP10))/NQRSc);
resultsdet10{end,11}=PI10;
xlswrite(filename,A,'Detektor_transformace','A1')
xlswrite(filename,resultsdet10,'Detektor_transformace','A2')
end



% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox1


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox2


% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox3


% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox4


% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox5


% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox6


% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox7


% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox8


% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox9


% --- Executes on button press in checkbox10.
function checkbox10_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox10


% --- Executes on button press in checkbox11.
function checkbox11_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global referencni
kes=get(handles.checkbox11,'Value');
if kes==1
    load('poziceQRSapoziceKES.mat');
    referencni=poziceQRSapoziceKES;
    set(handles.checkbox12,'Visible','off');
else
    load('poziceQRSvCSEv2.mat');
    referencni=poziceQRSvCSEv2;
    set(handles.checkbox12,'Visible','on');
end
% Hint: get(hObject,'Value') returns toggle state of checkbox11


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over checkbox11.
function checkbox11_ButtonDownFcn(hObject, eventdata, handles)

% hObject    handle to checkbox11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in checkbox12.
function checkbox12_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global referencni
a=get(handles.checkbox12,'Value');
if a==1
 load('QRSmanref.mat');
 referencni=QRSmanref;
 set(handles.checkbox11,'Visible','off');
 else
load('poziceQRSvCSEv2.mat')
referencni=poziceQRSvCSEv2;
set(handles.checkbox11,'Visible','on');
 end
% Hint: get(hObject,'Value') returns toggle state of checkbox12


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




function edit15_Callback(hObject, eventdata, handles)
% hObject    handle to edit15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit15 as text
%        str2double(get(hObject,'String')) returns contents of edit15 as a double


% --- Executes during object creation, after setting all properties.
function edit15_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global signal signaly svod polohy QRSref t
bod=ylim;
pomtex=max(signal);
fce =((get(handles.edit15,'String')));
fce = str2func(fce);
pom_fce=get(handles.radiobutton29,'Value')
if pom_fce==1;
[QRS]=fce(signaly);
else
[QRS]=fce(signal);
end
    QRS=QRS*0.002;
    axes(handles.axes3);
    cla
    xlabel('Čas [s]');
    ylabel('Napětí [uV]');
    line ([QRS;QRS],[bod],'color','red')
    hold on
    plot(t,signal)
    for i=1:length(QRS) 
    text(QRS(:,i),pomtex,num2str(i),'Color','r')
    end
    pocetDET=length(QRS);
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
set(handles.edit2,'String',TP);
set(handles.edit3,'String',FP);
set(handles.edit4,'String',FN);
set(handles.edit5,'String',Pplus);
set(handles.edit6,'String',SE);
set(handles.edit7,'String',pocetDET);
%%%%%ODCHYLKY%%%%%
set(handles.edit9,'String',minodchylka);
set(handles.edit10,'String',maxodchylka);
set(handles.edit11,'String',prumernaodchylka);
set(handles.edit16,'String',err);

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global pocet svod popisy referencni
fce =((get(handles.edit15,'string')));
fce = str2func(fce);
NQRSc=str2num(get(handles.edit18,'String'));
for i =1:pocet
    index_selected = i;
    list = get(handles.listbox1,'String');
    zaznam=list{index_selected}; 
    folder=get(handles.edit1,'String');
    fullFileName = fullfile(folder, zaznam);
    storedStructure = load(fullFileName);
    signals=storedStructure.x;
    onesignal=signals(svod,:);
if  size(referencni,2)>1
    load('poziceQRSvCSEv2.mat');
    referencni=poziceQRSvCSEv2;
end
QRSref=referencni{i,1};    
if max(QRSref)>10
    QRSref=QRSref*0.002;
end
pom_fce=get(handles.radiobutton29,'Value');
if pom_fce==1;
[QRS]=fce(signals);
else
[QRS]=fce(onesignal);
end  
    QRS=QRS*0.002;
    QRSref=QRSref;
[TP FP FN QRSfin Pplus SE maxodchylka minodchylka prumernaodchylka err PI]=statistic(QRS,QRSref);
    detQRS=length (QRS);
    resultsdetn{i,1}=detQRS;
    resultsdetn{i,2}=TP;
    resultsdetn{i,3}=FN;
    resultsdetn{i,4}=FP;
    resultsdetn{i,5}=SE;
    resultsdetn{i,6}=Pplus;
    resultsdetn{i,7}=minodchylka;
    resultsdetn{i,8}=maxodchylka;
    resultsdetn{i,9}=prumernaodchylka;
    resultsdetn{i,10}=PI;
    resultsdetn{i,11}=popisy{i,:};
end
alldetn=sum(cell2mat(resultsdetn(:,1)));
resultsdetn{end+1,1}=alldetn;
TP1n=sum(cell2mat(resultsdetn(:,2)));
resultsdetn{end,2}=TP1n;
FN1n=sum(cell2mat(resultsdetn(:,3)));
resultsdetn{end,3}=FN1n;
FP1n=sum(cell2mat(resultsdetn(:,4)));
resultsdetn{end,4}=FP1n;
SE1n=TP1n/(TP1n+FN1n);
resultsdetn{end,5}=SE1n;
pplus1n=TP1n/(TP1n+FP1n);
resultsdetn{end,6}=pplus1n;
PI1n=((NQRSc-(FN1n+FP1n))/NQRSc);
resultsdetn{end,10}=PI1n;

A={'N', 'TP','FN','FP','Senzitivita','Pozitivní prediktivita','Minimální odchylka','Maximální odchylka','Průměrná odchylka','Stručný popis'};
 filename = 'results_of_analysis_new_detector.xlsx';
xlswrite(filename,A,'New_detector','A1')
xlswrite(filename,resultsdetn,'New_detector','A2')
% --- Executes when selected object is changed in uipanel5.
function uipanel5_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel5 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global leads
new_dec_set=get(handles.radiobutton30,'Value');
if new_dec_set==1;
if leads== '12'
    set(handles.uipanel2,'Visible','on');
else
    set(handles.uipanel1,'Visible','on');
end
else
    set(handles.uipanel2,'Visible','off');
    set(handles.uipanel1,'Visible','off');
end


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
       set(handles.uipanel2,'Visible','off');
       set(handles.uipanel1,'Visible','off');



function edit16_Callback(hObject, eventdata, handles)
% hObject    handle to edit16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit16 as text
%        str2double(get(hObject,'String')) returns contents of edit16 as a double


% --- Executes during object creation, after setting all properties.
function edit16_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit17_Callback(hObject, eventdata, handles)
% hObject    handle to edit17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit17 as text
%        str2double(get(hObject,'String')) returns contents of edit17 as a double


% --- Executes during object creation, after setting all properties.
function edit17_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global referencni
filename = uigetfile('*.mat');
a = load(filename);
variablenames = fieldnames(a);
referencni = a.(variablenames{1});



function edit18_Callback(hObject, eventdata, handles)
% hObject    handle to edit18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit18 as text
%        str2double(get(hObject,'String')) returns contents of edit18 as a double


% --- Executes during object creation, after setting all properties.
function edit18_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit18 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit19_Callback(hObject, eventdata, handles)
% hObject    handle to edit19 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit19 as text
%        str2double(get(hObject,'String')) returns contents of edit19 as a double


% --- Executes during object creation, after setting all properties.
function edit19_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit19 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
