%% This script loads the file "abr_analysis_results.mat" from the same folder and plots the data

% load the data
%load('abr_deafening_results.mat')

% generate plot titles
titles={'< 2 weeks of age';'< 3 weeks of age';'6 months of age';'3 years of age'};

% plot bootstrap results and threshold
figure, 

% for 24 subplots (i.e. 4 measurements per individual)
for k=1:24
    subplot(6,4,k),
    % plot all measurements that have a bootstrap results above 0.95
    % confidence in green
    ph=plot(allCONFI(k).frequencies(find(allCONFI(k).confidences>0.95)),allCONFI(k).levels(find(allCONFI(k).confidences>0.95)),'ko');
    set(ph,'markerfacecolor','g')
    hold on,
    % plot all measurements that have a bootstrap results below 0.95
    % confidence as empty
    ph=plot(allCONFI(k).frequencies(find(allCONFI(k).confidences<=0.95)),allCONFI(k).levels(find(allCONFI(k).confidences<=0.95)),'ko');
    % set plot limits
    set(gca,'xlim',[5 90],'ylim',[40 120],'ytick',[40:40:120],'xscale','log','xtick',[5 10 20 40 90]);
    hold on,
    % plot the audiogram threshold line
    plot(resultTHRES(k).uniqueFrequencies,resultTHRES(k).bootstrapThresholds,'-k','linewidth',2);
    % set x- and y-axis labels
    set(gca,'xtick',[5 10 20 50 90])
    set(gca,'ytick',[40 80 120])
    % add titles and axis labels to plot
    if k == 1
        title(char(titles(k)),'FontSize',13);
        ylabel({['Deafened 1'] ; 'Level (dB SPL)' },'FontSize',11);
    elseif k==2 ||k==3|| k==4
        title(char(titles(k)),'FontSize',13);
    elseif k == 5
        ylabel({['Deafened 2'] ; 'Level (dB SPL)' },'FontSize',11);
    elseif k==9
        ylabel({['Deafened 3'] ; 'Level (dB SPL)' },'FontSize',11);
    elseif k==13
        ylabel({['Hearing 1'] ; 'Level (dB SPL)' },'FontSize',11);
    elseif k==17
        ylabel({['Hearing 2'] ; 'Level (dB SPL)' },'FontSize',11);
    elseif k == 21
        ylabel({['Hearing 3'] ; 'Level (dB SPL)' },'FontSize',11);
        xlabel('Frequency (kHz)','FontSize',11)
    elseif k == 22||k == 23||k == 24
        xlabel('Frequency (kHz)','FontSize',11)
    end
end