% Note: This dataset does not contain an encoding of confidence onset.

Pre = load('/Volumes/LNDG-1/Julian/Projects/DYNSAT/C_Paradigm/data/JQK_170705_v1/dotsX_behav_JQK_170705_v1_PreMAT_170705_1817.mat');
Post = load('/Volumes/LNDG-1/Julian/Projects/DYNSAT/C_Paradigm/data/JQK_170705_v1/dotsX_behav_JQK_170705_v1_PostMAT_170705_1907.mat');

Pre.ExperimentProtocol 

% get elapsed time between trial onsets & stimulus presentation duration (i.e. probe onset-first flip)

IndexOnsetPre = find(contains(Pre.ExperimentProtocol(:,1),'TrialOnset')); % R2016b
IndexOnsetPost = find(contains(Post.ExperimentProtocol(:,1),'TrialOnset')); % R2016b
IndexProbePre = find(contains(Pre.ExperimentProtocol(:,1),'RespOnset')); % R2016b
IndexProbePost = find(contains(Post.ExperimentProtocol(:,1),'RespOnset')); % R2016b

figure;
subplot(2,2,1);
    plot(diff(cell2mat(Pre.ExperimentProtocol(IndexOnsetPre,2)))); xlim([0 numel(Index)])
    title('Pre: TrialDuration'); ylabel('Duration [s]')
subplot(2,2,2);
    plot(diff(cell2mat(Post.ExperimentProtocol(IndexOnsetPost,2)))); xlim([0 numel(Index)])
    title('Post: TrialDuration'); ylabel('Duration [s]')
subplot(2,2,3);
    plot((cell2mat(Pre.ExperimentProtocol(IndexProbePre,2))-cell2mat(Pre.ExperimentProtocol(IndexOnsetPre+1,2))).*1000); xlim([0 numel(Index)])
    title('Pre: stim duration'); ylabel('Duration [ms]')
subplot(2,2,4);
    plot((cell2mat(Post.ExperimentProtocol(IndexProbePost,2))-cell2mat(Post.ExperimentProtocol(IndexOnsetPost+1,2))).*1000); xlim([0 numel(Index)])
    title('Post: stim duration'); ylabel('Duration [ms]')

% get amount of flips per presentation duration (i.e. flicker rate)

updateAmount = (IndexProbePost-IndexOnsetPost-1);
presentationDuration = (cell2mat(Post.ExperimentProtocol(IndexProbePost,2))-cell2mat(Post.ExperimentProtocol(IndexOnsetPost+1,2)));

figure; 
plot(updateAmount./presentationDuration); xlim([0 numel(Index)]);
title('MAT Update Rate'); ylabel('Presentation Frequency [Hz]'); xlabel('Trial')

