function  plot_by_ring_predict( gap, data1,data2, frequency,info)
figure('name',info,'numbertitle','off');
index = frequency;
freq = getIndex('Q1',index);
%remove baseline
% meanD1 = mean(data1,3);
% meanD2 = mean(data2,3);
% for t = 1:size(data1,3)
%     data1(:,:,t) = data1(:,:,t)-meanD1;
% end
% for t = 1:size(data2,3)
%     data2(:,:,t) = data2(:,:,t)-meanD2;
% end

for q = 1:length(freq)
    temp = squeeze(mean(data1,3));
    %[temp,b] = sort(temp,2,'descend');
    %     temp = temp-repmat(mean(temp,2),1,size(temp,2));
    tempMAX = squeeze(max(data1,[],3));
    tempMIN = squeeze(min(data1,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    subplot(6,6,mfSSVEP_ring_plot(index(freq(q))));
    plot(gap,temp(freq(q),gap),'r','LineWidth',1.5);
    hold on;
    plot(gap,tempMAX(freq(q),gap),'--r','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--r','LineWidth',1);
    
    temp2 = squeeze(mean(data2,3));
    %[temp2,b] = sort(temp2,2,'descend');
    %     temp2 = temp2-repmat(mean(temp2,2),1,size(temp2,2));
    tempMAX = squeeze(max(data2,[],3));
    tempMIN = squeeze(min(data2,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    
    plot(gap,temp2(freq(q),gap),'k','LineWidth',2);
    plot(gap,tempMAX(freq(q),gap),'--k','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--k','LineWidth',1);
    %title([num2str(index(freq(q))) ' hz, ' 'r= ' num2str(corr2(temp(freq(q),1:gap:size(data1,2)),temp2(freq(q),1:gap:size(data2,2))))]);
    title([num2str(index(freq(q))) ' hz, ' ...
        'd= ' num2str(sum(abs(temp(freq(q),gap)-(temp2(freq(q),gap))))) ...
        'r= ' num2str(corr2((temp(freq(q),gap)),(temp2(freq(q),gap))))]);
    %     plot(1:gap:size(data1,2),data2(freq(q),:)-data1(freq(q),:),'g','LineWidth',2);
    %     plot(1:gap:size(data1,2),temp2(freq(q),:)-temp(freq(q),:),'b','LineWidth',2);
    %     ylim([-150 250]);
    
    %     temp3 = squeeze(mean(data3,3));
    %     tempSTD = std(temp3);
    %     tempMAX = squeeze(max(data3,[],3));
    %     tempMIN = squeeze(min(data3,[],3));
    %     plot(1:gap:size(data3,2),temp3(freq(q),1:gap:size(data3,2)),'b','LineWidth',2);
    %     plot(1:gap:size(data3,2),tempMAX(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     plot(1:gap:size(data3,2),tempMIN(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     %legend('Normal', 'Block9Hz');
    %     hold off
    %     title(index(freq(q)));
    %     %ylim([0.2 0.5]);
end

freq = getIndex('Q2',index);
for q = 1:length(freq)
    temp = squeeze(mean(data1,3));
    %[temp,b] = sort(temp,2,'descend');
    %     temp = temp-repmat(mean(temp,2),1,size(temp,2));
    tempMAX = squeeze(max(data1,[],3));
    tempMIN = squeeze(min(data1,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    subplot(6,6,mfSSVEP_ring_plot(index(freq(q))));%subplot(length(freq),1,q);
    plot(gap,temp(freq(q),gap),'r','LineWidth',2);
    hold on;
    plot(gap,tempMAX(freq(q),gap),'--r','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--r','LineWidth',1);
    
    temp2 = squeeze(mean(data2,3));
    %[temp2,b] = sort(temp2,2,'descend');
    %     temp2 = temp2-repmat(mean(temp2,2),1,size(temp2,2));
    tempMAX = squeeze(max(data2,[],3));
    tempMIN = squeeze(min(data2,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    plot(gap,temp2(freq(q),gap),'k','LineWidth',2);
    plot(gap,tempMAX(freq(q),gap),'--k','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--k','LineWidth',1);
    %title([num2str(index(freq(q))) ' hz, ' 'r= ' num2str(corr2(temp(freq(q),1:gap:size(data1,2)),temp2(freq(q),1:gap:size(data2,2))))]);
        title([num2str(index(freq(q))) ' hz, ' ...
        'd= ' num2str(sum(abs(temp(freq(q),gap)-(temp2(freq(q),gap))))) ...
        'r= ' num2str(corr2((temp(freq(q),gap)),(temp2(freq(q),gap))))]);
    %     plot(1:gap:size(data1,2),data2(freq(q),:)-data1(freq(q),:),'g','LineWidth',2);
    %     plot(1:gap:size(data1,2),temp2(freq(q),:)-temp(freq(q),:),'b','LineWidth',2);
    %     ylim([-150 250]);
    
    %     temp3 = squeeze(mean(data3,3));
    %     tempSTD = std(temp3);
    %     tempMAX = squeeze(max(data3,[],3));
    %     tempMIN = squeeze(min(data3,[],3));
    %     plot(1:gap:size(data3,2),temp3(freq(q),1:gap:size(data3,2)),'b','LineWidth',2);
    %     plot(1:gap:size(data3,2),tempMAX(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     plot(1:gap:size(data3,2),tempMIN(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     %legend('Normal', 'Block9Hz');
    %     hold off
    %     title(index(freq(q)));
    %     %ylim([0.2 0.5]);
end
freq = getIndex('Q3',index);
for q = 1:length(freq)
    temp = squeeze(mean(data1,3));
    %[temp,b] = sort(temp,2,'descend');
    %     temp = temp-repmat(mean(temp,2),1,size(temp,2));
    tempMAX = squeeze(max(data1,[],3));
    tempMIN = squeeze(min(data1,[],3));
    
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    subplot(6,6,mfSSVEP_ring_plot(index(freq(q))));%subplot(length(freq),1,q);
    plot(gap,temp(freq(q),gap),'r','LineWidth',2);
    hold on;
    plot(gap,tempMAX(freq(q),gap),'--r','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--r','LineWidth',1);
    
    temp2 = squeeze(mean(data2,3));
    %[temp2,b] = sort(temp2,2,'descend');
    %     temp2 = temp2-repmat(mean(temp2,2),1,size(temp2,2));
    tempMAX = squeeze(max(data2,[],3));
    tempMIN = squeeze(min(data2,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    plot(gap,temp2(freq(q),gap),'k','LineWidth',2);
    plot(gap,tempMAX(freq(q),gap),'--k','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--k','LineWidth',1);
    %title([num2str(index(freq(q))) ' hz, ' 'r= ' num2str(corr2(temp(freq(q),1:gap:size(data1,2)),temp2(freq(q),1:gap:size(data2,2))))]);
    title([num2str(index(freq(q))) ' hz, ' ...
        'd= ' num2str(sum(abs(temp(freq(q),gap)-(temp2(freq(q),gap))))) ...
        'r= ' num2str(corr2((temp(freq(q),gap)),(temp2(freq(q),gap))))]);
    %     plot(1:gap:size(data1,2),data2(freq(q),:)-data1(freq(q),:),'g','LineWidth',2);
    %     plot(1:gap:size(data1,2),temp2(freq(q),:)-temp(freq(q),:),'b','LineWidth',2);
    %     ylim([-150 250]);
    
    %     temp3 = squeeze(mean(data3,3));
    %     tempSTD = std(temp3);
    %     tempMAX = squeeze(max(data3,[],3));
    %     tempMIN = squeeze(min(data3,[],3));
    %     plot(1:gap:size(data3,2),temp3(freq(q),1:gap:size(data3,2)),'b','LineWidth',2);
    %     plot(1:gap:size(data3,2),tempMAX(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     plot(1:gap:size(data3,2),tempMIN(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     %legend('Normal', 'Block9Hz');
    %     hold off
    %     title(index(freq(q)));
end

freq = getIndex('Q4',index);
for q = 1:length(freq)
    temp = squeeze(mean(data1,3));
    %[temp,b] = sort(temp,2,'descend');
    %     temp = temp-repmat(mean(temp,2),1,size(temp,2));
    tempMAX = squeeze(max(data1,[],3));
    tempMIN = squeeze(min(data1,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    subplot(6,6,mfSSVEP_ring_plot(index(freq(q))));%subplot(length(freq),1,q);
    plot(gap,temp(freq(q),gap),'r','LineWidth',2);
    hold on;
    plot(gap,tempMAX(freq(q),gap),'--r','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--r','LineWidth',1);
    
    temp2 = squeeze(mean(data2,3));
    %[temp2,b] = sort(temp2,2,'descend');
    %     temp2 = temp2-repmat(mean(temp2,2),1,size(temp2,2));
    tempMAX = squeeze(max(data2,[],3));
    tempMIN = squeeze(min(data2,[],3));
    %     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
    %     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
    plot(gap,temp2(freq(q),gap),'k','LineWidth',2);
    plot(gap,tempMAX(freq(q),gap),'--k','LineWidth',1);
    plot(gap,tempMIN(freq(q),gap),'--k','LineWidth',1);
    %title([num2str(index(freq(q))) ' hz, ' 'r= ' num2str(corr2(temp(freq(q),1:gap:size(data1,2)),temp2(freq(q),1:gap:size(data2,2))))]);
    title([num2str(index(freq(q))) ' hz, ' ...
        'd= ' num2str(sum(abs(temp(freq(q),gap)-(temp2(freq(q),gap))))) ...
        'r= ' num2str(corr2((temp(freq(q),gap)),(temp2(freq(q),gap))))]);
    %     plot(1:gap:size(data1,2),data2(freq(q),:)-data1(freq(q),:),'g','LineWidth',2);
    %     plot(1:gap:size(data1,2),temp2(freq(q),:)-temp(freq(q),:),'b','LineWidth',2);
    %     ylim([-150 250]);
    
    %     temp3 = squeeze(mean(data3,3));
    %     tempSTD = std(temp3);
    %     tempMAX = squeeze(max(data3,[],3));
    %     tempMIN = squeeze(min(data3,[],3));
    %     plot(1:gap:size(data3,2),temp3(freq(q),1:gap:size(data3,2)),'b','LineWidth',2);
    %     plot(1:gap:size(data3,2),tempMAX(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     plot(1:gap:size(data3,2),tempMIN(freq(q),1:gap:size(data3,2)),'--b','LineWidth',1);
    %     %legend('Normal', 'Block9Hz');
    %     hold off
    %     title(index(freq(q)));
end
tightfig;

%% individual figure
% freq = [5, 6, 7];
% for q = 1:length(freq)
%     figure('name',[info ',' num2str(index(freq(q))) ' Hz'],'numbertitle','off');
%     temp = squeeze(mean(data1,3));
%     %[temp,b] = sort(temp,2,'descend');
%     temp = temp-repmat(mean(temp,2),1,size(temp,2));
%     tempMAX = squeeze(max(data1,[],3));
%     tempMIN = squeeze(min(data1,[],3));
%     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
%     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
% %     plot(mfSSVEP_ring_plot(index(freq(q))));%subplot(length(freq),1,q);
%     hold on;
%     plot(1:gap:size(data1,2),temp(freq(q),1:gap:size(data1,2)),'r','LineWidth',2);
%     plot(1:gap:size(data1,2),tempMAX(freq(q),1:gap:size(data1,2)),'--r','LineWidth',1);
%     plot(1:gap:size(data1,2),tempMIN(freq(q),1:gap:size(data1,2)),'--r','LineWidth',1);
%
%     temp2 = squeeze(mean(data2,3));
%     %[temp2,b] = sort(temp2,2,'descend');
%     temp2 = temp2-repmat(mean(temp2,2),1,size(temp2,2));
%     tempMAX = squeeze(max(data2,[],3));
%     tempMIN = squeeze(min(data2,[],3));
%     tempMAX = tempMAX - repmat(mean(tempMAX,2),1,size(tempMAX,2));
%     tempMIN = tempMIN - repmat(mean(tempMIN,2),1,size(tempMIN,2));
%     plot(1:gap:size(data2,2),temp2(freq(q),1:gap:size(data2,2)),'k','LineWidth',2);
%     plot(1:gap:size(data2,2),tempMAX(freq(q),1:gap:size(data2,2)),'--k','LineWidth',1);
%     plot(1:gap:size(data2,2),tempMIN(freq(q),1:gap:size(data2,2)),'--k','LineWidth',1);
%     %title([num2str(index(freq(q))) ' hz, ' 'r= ' num2str(corr2(temp(freq(q),1:gap:size(data1,2)),temp2(freq(q),1:gap:size(data2,2))))]);
%     %title([num2str(index(freq(q))) ' hz, ' 'd= ' num2str(sum(abs(temp(freq(q),1:gap:size(data1,2))-temp2(freq(q),1:gap:size(data2,2)))))]);
%     %title([num2str(index(freq(q))) ' Hz']);
%     box off;
%     ylabel('uV');
%     xlabel('Trials');
%     set(gca,'fontsize',20)
%     hold off;
% end
% %%
% freq = [5, 6, 7];
% figure('name',info,'numbertitle','off');
% for q = 1:length(freq)
%     if q==1
%         colors = 'r';
%     elseif q==2
%         colors = 'g';
%     elseif q==3
%         colors = 'b';
%     end
%     temp = squeeze(mean(data1,3));
% %     plot(mfSSVEP_ring_plot(index(freq(q))));%subplot(length(freq),1,q);
%     hold on;
%     plot(1:gap:size(data1,2),temp(freq(q),1:gap:size(data1,2)),colors,'LineWidth',2);
%
%     temp2 = squeeze(mean(data2,3));
%     plot(1:gap:size(data2,2),temp2(freq(q),1:gap:size(data2,2)),colors,'LineWidth',2);
%
% end
%     box off;
%     ylabel('Power (dB)');
%     xlabel('Trials');
%     set(gca,'fontsize',20)
%
end
%%
function indexx = getIndex(location,freq)
if(length(freq)==20)
    if(strcmpi(location,'Q1'))
        indexx = [1, 5, 6, 13, 14];
    elseif(strcmpi(location,'Q2'))
        indexx = [4,11,12,19,20];
    elseif(strcmpi(location,'Q3'))
        indexx = [3,9,10,17,18];
    elseif(strcmpi(location,'Q4'))
        indexx = [2, 7, 8, 15, 16];
    end
else
    if(strcmpi(location,'Q1'))
        indexx = [1, 9,11,25,27];
    elseif(strcmpi(location,'Q2'))
        indexx = [7,21,23,37,39];
    elseif(strcmpi(location,'Q3'))
        indexx = [5,17,19,33,35];
    elseif(strcmpi(location,'Q4'))
        indexx = [3,13,15,29,31];
    end
end
end
%%
function qqq = getPlotIndex(freq)
if(freq ==8)
    qqq = 16;
elseif(freq ==8.2)
    qqq = 22;
elseif(freq == 8.4)
    qqq = 21;
elseif(freq == 8.6)
    qqq = 15;
elseif(freq ==8.8)
    qqq = 10;
elseif(freq ==9)
    qqq = 17;
elseif(freq ==9.2)
    qqq = 23;
elseif(freq ==9.4)
    qqq = 28;
elseif(freq ==9.6)
    qqq = 27;
elseif(freq ==9.8)
    qqq = 20;
elseif(freq ==10)
    qqq = 14;
elseif(freq ==10.2)
    qqq = 9;
elseif(freq ==10.4)
    qqq = 5;
elseif(freq ==10.6)
    qqq = 12;
elseif(freq ==10.8)
    qqq = 30;
elseif(freq ==11)
    qqq = 35;
elseif(freq ==11.2)
    qqq = 32;
elseif(freq ==11.4)
    qqq = 25;
elseif(freq ==11.6)
    qqq = 7;
elseif(freq ==11.8)
    qqq = 2;
    
end
end
