function outputStruct = calculateDecodePerformance(header,subjectStruct,svmopts)
outputStruct = struct;
RANDOMIZE_DATAPOINTS = header.svmrnd;
NAN_AS_ZERO = header.nantozero;

timeline = header.timeline;
timeline.frameShiftStart = header.frameShift.frameShiftStart;
timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
timeline.decodeDuration  = header.frameShift.decodeDuration;

timeLineStart  = timeline.frameShiftStart;
timeLineEnd    = timeline.frameShiftEnd;

timePointArgs.pst           = subjectStruct.pst;
timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
timePointArgs.eventList     = header.classDef.eventMatrix;

timePointMatrix = buildTimePointMatrix(timeline,timePointArgs);

decodePerformance = [];
for index = 1:timeLineEnd-timeLineStart+1

    svmdata      = timePointMatrix{index}(:,2:size(timePointMatrix{index},2));
    svmdata      = header.timeframeGroupingfunction(svmdata);
    svmlabel     = timePointMatrix{index}(:,1);

    if RANDOMIZE_DATAPOINTS
        rndindex  = randperm(length(svmlabel));
        svmdata   = svmdata(rndindex,:);
        svmlabel  = svmlabel(rndindex);
    end

    if NAN_AS_ZERO
        svmdata(isnan(svmdata))=0;
    end
    decodePerformance = [decodePerformance; svm_single_crossval(svmlabel,svmdata,svmopts)];
end

outputStruct.decodePerformance  = decodePerformance;
outputStruct.svmdata            = svmdata;
outputStruct.svmlabel           = svmlabel;
outputStruct.rawTimeCourse      = subjectStruct.pst;
% outputStruct.minPerformance     = minPerformance;
% outputStruct.maxPerformance     = maxPerformance;
end