blockVec = 0:20:size(trialData,2);

for block = 1:numel(blockVec)-1
    curData = trialData(blockVec(block)+1:blockVec(block+1));
    lowTrials = find([curData.level] == .01);
    intTrials = find([curData.level] == .03);
    highTrials = find([curData.level] == .07);
    
    acc(1,block) = nanmean([curData(lowTrials).correct]);
    acc(2,block) = nanmean([curData(intTrials).correct]);
    acc(3,block) = nanmean([curData(highTrials).correct]);
    
    rt(1,block) = nanmean([curData(lowTrials).rxtime]);
    rt(2,block) = nanmean([curData(intTrials).rxtime]);
    rt(3,block) = nanmean([curData(highTrials).rxtime]);
    
end;

% plots

figure;
subplot(2,1,1);
plot(acc'); legend({'low'; 'int'; 'high'});
subplot(2,1,2);
plot(rt'); legend({'low'; 'int'; 'high'});

% images

figure;
subplot(2,1,1);
imagesc(acc); title('Accuracy'); colorbar;
subplot(2,1,2);
imagesc(rt); title('RTs'); colorbar;


%% sort by mean contrast

blockVec = 0:36:size(trialData,2);

for block = 1:numel(blockVec)-1
    curData = trialData(blockVec(block)+1:blockVec(block+1));
    
    lowTrials = find([curData.level] == .01);
    intTrials = find([curData.level] == .03);
    highTrials = find([curData.level] == .07);
   
    levels = {'lowTrials'; 'intTrials'; 'highTrials'};
    
    for indLevel = 1:numel(levels)
        acc(indLevel,block) = nanmean([curData(eval(levels{indLevel})).correct]);
        rt(indLevel,block) = nanmean([curData(eval(levels{indLevel})).rxtime]);
    end;
    
end;

lowMean = find(checkerInfo.contrastBlocks ==.3);
interMean = find(checkerInfo.contrastBlocks ==.5);
highMean = find(checkerInfo.contrastBlocks ==.8);

figure;
subplot(2,3,1);
imagesc(acc(:,lowMean)); title('Accuracy'); colorbar;
subplot(2,3,2);
imagesc(acc(:,interMean)); title('Accuracy'); colorbar;
subplot(2,3,3);
imagesc(acc(:,highMean)); title('Accuracy'); colorbar;

subplot(2,3,4);
imagesc(rt(:,lowMean)); title('RTs'); colorbar;
subplot(2,3,5);
imagesc(rt(:,interMean)); title('RTs'); colorbar;
subplot(2,3,6);
imagesc(rt(:,highMean)); title('RTs'); colorbar;

% show as plots

figure;
subplot(2,3,1);
plot(acc(:,lowMean)'); legend({'low'; 'int'; 'high'}); ylim([0 1]); xlim([1 6]);
title('Accuracy: .3 mean contrast');
subplot(2,3,2);
plot(acc(:,interMean)'); legend({'low'; 'int'; 'high'}); ylim([0 1]); xlim([1 6]);
title('Accuracy: .5 mean contrast');
subplot(2,3,3);
plot(acc(:,highMean)'); legend({'low'; 'int'; 'high'}); ylim([0 1]); xlim([1 6]);
title('Accuracy: .8 mean contrast');

subplot(2,3,4);
plot(rt(:,lowMean)'); legend({'low'; 'int'; 'high'}); ylim([0 2.5]); xlim([1 6]);
title('RT: .3 mean contrast');
subplot(2,3,5);
plot(rt(:,interMean)'); legend({'low'; 'int'; 'high'}); ylim([0 2.5]); xlim([1 6]);
title('RT: .5 mean contrast');
subplot(2,3,6);
plot(rt(:,highMean)'); legend({'low'; 'int'; 'high'}); ylim([0 2.5]); xlim([1 6]);
title('RT: .8 mean contrast');
set(findall(gcf,'-property','FontSize'),'FontSize',18)

