private/plotDecodePerformance.m
27ebd4d9
 function plotDecodePerformance(type,decode,subjectData)
e370a509
 
27ebd4d9
 header = decode.header;
d0eb71ff
 timeline = header.timeline;
27ebd4d9
 frameshift = header.frameShift;
d0eb71ff
 
c73e97a6
 psthStart         = timeline.psthStart;
 psthEnd           = timeline.psthEnd;
27ebd4d9
 frameStart        = frameshift.frameShiftStart;
 frameEnd          = frameshift.frameShiftEnd;
84376774
 
c73e97a6
 nClasses          = numel(header.classDef.labelCells);
 decodePerformance = decode.decodePerformance;
 psth              = decode.rawTimeCourse;
 SubjectID         = subjectData;
d0eb71ff
 
27ebd4d9
 nSubjects         = size(SubjectID,2);
84376774
 
625fdcd6
 nTrials           = getNTrials(psth);
2095645b
 
     f = figure;
18bc821f
   
2095645b
     hold on;
     chanceLevel = 100/nClasses;
625fdcd6
 
2095645b
     axis([psthStart psthEnd 0 100])
bdba063a
     xlabel('time [sec]');
     ylabel('decode performance [%]');
4dbef185
 
27ebd4d9
     switch type
18bc821f
         case 'psth'
             plotPSTH(psth,psthStart,psthEnd);  
27ebd4d9
         case 'simple'
             plotDecodePerformanceWithSE(frameStart,frameEnd,decodePerformance)
         case 'class performance'
             plotClassPerformance(frameStart,frameEnd,decodePerformance,nClasses)
c73e97a6
         case 'x-subject-val'
             for c = 1:nSubjects
                 plot(frameStart:frameEnd, decodePerformance(:,c) ,[colorChooser(mod(c,nSubjects)+3) '-']);
             end
27ebd4d9
             plotDecodePerformanceWithSE(frameStart,frameEnd,decodePerformance)
4dbef185
     end
625fdcd6
     
     plot([psthStart psthEnd],[chanceLevel chanceLevel],'k:');
 
     plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.05,chanceLevel/100,'r');
     plotBinConfidenceIntervall(psthStart,psthEnd,nTrials,0.01,chanceLevel/100,'g');
     
2095645b
     hold off;
06612a42
     
27ebd4d9
 %     setTitle(f,header,decode,subjectData);
     
 end
 
625fdcd6
 function plotBinConfidenceIntervall(pStart,pEnd,nTrials,alpha,limit,color)
     [pLevel Z] = rev_ki_bin(nTrials,alpha,limit);
     [lower upper proz] = ki_bin(Z,nTrials,alpha);
 
     plot([pStart pEnd],[pLevel*100 pLevel*100],[color ':']);
 
     plot([pStart pEnd],[lower*100 lower*100],[color '-.']);
     plot([pStart pEnd],[upper*100 upper*100],[color '-.']);
 end
 
 function n = getNTrials(psth)
 nSubjects = size(psth,2);
 
 n = 0;
 for ns = 1:nSubjects
     nClasses = size(psth{ns},2);
     for nc = 1:nClasses
         n = n + size(psth{ns}{nc},1);
     end
 end
 end
 
27ebd4d9
 function plotClassPerformance(frameStart,frameEnd,decodePerformance,nClasses)
 for c = 1:size(decodePerformance,2)
     plot(frameStart:frameEnd, decodePerformance(:,c) ,[colorChooser(mod(c,nClasses)+3) '-']);
 end
 plot(frameStart:frameEnd, mean(decodePerformance,2) ,'b','LineWidth',2);
 end
2095645b
 
27ebd4d9
 function plotDecodePerformanceWithSE(frameStart,frameEnd,decodePerformance)
 plot(frameStart:frameEnd, mean(decodePerformance,2) ,'b','LineWidth',2);
 
 se = myStdErr(decodePerformance,2);
 plot(frameStart:frameEnd, mean(decodePerformance,2)+se ,'b:');
 plot(frameStart:frameEnd, mean(decodePerformance,2)-se ,'b:');
 end
2095645b
 
27ebd4d9
 
 function plotPSTH(psth,psthStart,psthEnd)
 
 PSTH_AXIS_MIN = -2;
 PSTH_AXIS_MAX = 2;
 
     hold on;
     if (size(psth) > 0)
       for voxel = 1:size(psth,2)
           for label = 1:size(psth{voxel},2)
               psthData = [];
               for timepoint = 1:size(psth{voxel}{label},2)
                   psthData = nanmean(psth{voxel}{label});
               end
625fdcd6
               PSTH_AXIS_MAX = max(PSTH_AXIS_MAX,nanmax(psthData));
27ebd4d9
               plot(psthStart:psthEnd,psthData,[colorChooser(voxel), lineStyleChooser(label)]);
           end
       end
     end
     axis([psthStart psthEnd PSTH_AXIS_MIN PSTH_AXIS_MAX])
     xlabel('time [sec]');
     ylabel('fMRI-signal change [%]');
     hold off
2095645b
 end
 
84376774
 
2095645b
 function color = colorChooser(n)
     switch (mod(n,8))
     case 0
         color = 'r';
4dbef185
     case 1
         color = 'g';
2095645b
     case 2
         color = 'b';
     case 3
4dbef185
         color = 'c';
     case 4
         color = 'm';
     case 5
         color = 'y';
2095645b
     otherwise
         color = 'k';
     end
 end
 
 function style = lineStyleChooser(n)
 switch(mod(n,4))
     case 0
       style = '--';
     case 1
         style = '-';
     case 2 
         style = ':';
     case 3
291ee33d
         style = '-.';
2095645b
 end
 end