%% leave-one-trial-out

%data: (ch*time*trial)
%excludeTrials: the trials index of input data i.e. template should not include these
%        trials
%tempLate: the training data

function [ out ] = myCCA3_2( data , excludeTrials, tempLate)

numTrials = (1:size(data,3));
newData = squeeze(mean(data(:,:,excludeTrials),3))';

freq = 8:0.2:11.8;

for index = 1:length(freq)
    template=[];
    template = squeeze(mean(tempLate,3))';
    template = myNotch(512,template',freq(index))';
    %template = squeeze(mean(testing(:,:,numTrials(~ismember(numTrials,numTrials(excludeTrials)))),3))';
    
    if(isempty(numTrials(~ismember(numTrials,numTrials(excludeTrials)))))%
        [A,B,r,U,V] = canoncorr(newData,newData);
    else
        [A,B,r,U,V] = canoncorr(newData,template);
    end
    out(index) = r(1);
end


% numTrials = (1:size(data,3));
% newData = data(:,:,excludeTrials);
% template = data(:,:,numTrials(~ismember(numTrials,numTrials(excludeTrials))));
% [A,B,r,U,V] = canoncorr(newData,template);
% out = r(1);

end

