% 'E' : left arrow and 'F' : right arrow
% Starts with the hand placed ON THE LAP, then UPPER LEFT CORNER, LOWER LEFT, LOWER RIGHT, UPPER RIGHT corners 

clear all

sub_name = input('Enter the name of subject - ', 's');
sub_no = input('Enter the subject number - ');
currentFolder = pwd;
dbase = strcat(currentFolder,'\Run2_', sub_name,'_',num2str(sub_no),'.xls');
HideCursor;

something = 0;
hand_quad = [];
Target_cond = [];
target_quad = [];
target_dist = [];
targ_dist = [];
X1 = [];
X2 = [];
X3 = [];
X4 = [];
X5 = [];
Y1 = [];
Y2 = [];
Y3 = [];
Y4 = [];
Y5 = [];
E_key = 'left';
F_key = 'right';
kc_E = KbName(E_key);
kc_F = KbName(F_key);
setsize_cond = [];
keys = [];
time = [];
feedback = [];

attrib = xlsread('run2-input.xlsx');
[wPtr,rect]=Screen('OpenWindow',0);
black=BlackIndex(wPtr);
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
xcenter = rect(3)/2;
ycenter = rect(4)/2;
xres=1280;
yres=1024;

rand_trial1 = randperm(100);
rand_trial2 = randperm(100);
rand_trial3 = randperm(100);
rand_trial4 = randperm(100);
rand_trial5 = randperm(100);
trial_no = length(attrib);

text1 = 'Keep your left hand on the UPPER LEFT CORNER of the screen';
text2 = 'Keep your left hand on the LOWER LEFT CORNER of the screen';
text3 = 'Keep your left hand on the LOWER RIGHT CORNER of the screen';
text4 = 'Keep your left hand on the UPPER RIGHT CORNER of the screen';

ready = 'Press any key when ready';

width=RectWidth(Screen('TextBounds',wPtr,text1));
Screen('TextSize', wPtr, 22);
Screen('TextStyle', wPtr , 1);
text = 'Please keep LEFT HAND on your lap';
Screen('DrawText', wPtr,text, xcenter-260,ycenter, [255 255 255]);
Screen('DrawText', wPtr,ready, xcenter-width/4,ycenter+50, [255 255 255]);
Screen(wPtr, 'Flip');
a= KbWait([],2);

for j=1:trial_no;
    
    if j<=100
        i=rand_trial1(j);
    elseif j>100 && j<=200
        i = rand_trial2(j-100)+100;
    elseif j>200 && j<=300
        i = rand_trial3(j-200)+200;
    elseif j>300 && j<=400
        i = rand_trial4(j-300)+300;
    elseif j>400
        i = rand_trial5(j-400)+400;
    end
    
    Screen('TextSize', wPtr, 22);
    Screen('TextStyle', wPtr , 1);
    
    if j==101
        
        Screen('DrawText', wPtr,text1, xcenter-450,ycenter, [255 255 255]);
        Screen('DrawText', wPtr,ready, xcenter-width/4,ycenter+50, [255 255 255]);
        Screen(wPtr, 'Flip');
        a= KbWait([],2);
    end
    FlushEvents
    
    if j==201
        
        Screen('DrawText', wPtr,text2, xcenter-450,ycenter, [255 255 255]);
        Screen('DrawText', wPtr,ready, xcenter-width/4,ycenter+50, [255 255 255]);
        Screen(wPtr, 'Flip');
        b= KbWait([],[2]);
    end
    FlushEvents
    if j==301
        
        Screen('DrawText', wPtr,text3, xcenter-450,ycenter, [255 255 255]);
        Screen('DrawText', wPtr,ready, xcenter-width/4,ycenter+50, [255 255 255]);
        Screen(wPtr, 'Flip');
        c = KbWait([],[2]);
    end
    FlushEvents
    if j==401
        
        Screen('DrawText', wPtr,text4, xcenter-450,ycenter, [255 255 255]);
        Screen('DrawText', wPtr,ready, xcenter-width/4,ycenter+50, [255 255 255]);
        Screen(wPtr, 'Flip');
        d = KbWait([],[2]);
    end
    FlushEvents
    
    Screen('TextSize', wPtr, 22);
    Screen('TextStyle', wPtr , 1);
    flushevents();
    
    Screen('DrawText', wPtr, '+', 640,512, [255 255 255]);
    Screen(wPtr, 'Flip');
    tic
    while toc<1;
    end
    
    if attrib(i, 1)==1           % When hand in upper right corner
        
        handX = 1280;
        handY = 0;
        h_quad = 'UR';
        hand_quad = strvcat(hand_quad, h_quad);
        
        if attrib(i, 5)==1       % Only near; upper right corner
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'near';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4
                
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(21);
                LTx = [541, 563, 660, 650, 653,   725, 820, 787, 827, 900,     980, 1009, 1117, 1175, 850,   960, 983, 1053, 1113,   1167, 1177];
                LTy = [50, 240, 90, 193, 361,     279, 391, 195, 100, 277,     165, 80, 241, 95, 499,        549, 379, 461, 615,     505, 371];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = cat(1, Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = cat(1, Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = strvcat(feedback, feed);
            end
            
            
            
            
            if attrib(i, 4)==2 % SS 7
                
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(21);
                LTx = [541, 563, 660, 650, 653,   725, 820, 787, 827, 900,     980, 1009, 1117, 1175, 850,   960, 983, 1053, 1113,   1167, 1177];
                LTy = [50, 240, 90, 193, 361,     279, 391, 195, 100, 277,     165, 80, 241, 95, 499,        549, 379, 461, 615,     505, 371];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M', 'N', 'P', 'Z'];
                    Target = 'E';
                    Target_cond = cat(1, Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M', 'N', 'P', 'Z'];
                    Target = 'F';
                    Target_cond = cat(1, Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = strvcat(feedback, feed);
            end
        end
        
        
        
        
        if attrib(i, 5)==2       % Target falling only in the far region from the upper right corner
            t_quad = 'LL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Far';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4
                
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(22);
                
                LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
                LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
            end
            
            
            
            if attrib(i, 4)==2 % SS 7
                
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(22);
                
                LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
                LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M', 'N', 'P', 'Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M', 'N', 'P', 'Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
            end
        end
    end
    
    
    if attrib(i, 1)==2           % When hand in upper left corner
        handX = 0;
        handY = 0;
        h_quad = 'UL';
        hand_quad = strvcat(hand_quad, h_quad);
        
        
        if attrib(i, 5)==1       % Target falling only in the NEAR region of the upper left corner
            
            t_quad = 'UL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Near';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4
                
                setsize = '4';
                setsize_cond = strvcat(setsize_cond, setsize);
                
                x1 = randperm(21);
                
                LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
                LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
            end
            
            
            
            if attrib(i, 4)==2 % SS 7
                
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(21);
                LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
                LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
            end
            
            
            
        end
        
        if attrib(i, 5)==2       % Target falling only in the FAR region from the upper left corner
            t_quad = 'LR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Far';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4
                
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(23);
                
                LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
                LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                    
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
            
            if attrib(i, 4)==2 % SS 7
                
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(23);
                
                LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
                LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M', 'N','P','Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                    
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
        end
    end
    
    
    
    if attrib(i, 1)==3           % When hand in the lower left corner
        handX = 0;
        handY = 1024;
        h_quad = 'LL';
        hand_quad = strvcat(hand_quad, h_quad);
        
        if attrib(i, 5)==1       % Target falling only in the NEAR region in the lower left corner
            t_quad = 'LL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Near';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4 in the NEAR region of the lower left corner
                
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(22);
                
                LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
                LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
            end
            
            if attrib(i, 4)==2 % SS 7 in the near region of lower left corner
                
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(22);
                
                LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
                LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
            end
        end
        
        
        if attrib(i, 5)==2       % Target falling only in the FAR region from the lower left corner
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Far';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4 falling in the FAR region from the lower left corner
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(21);
                
                LTx = [541, 563, 660, 650, 653, 725, 820, 787, 827, 900, 980, 1009, 1117, 1175, 850, 960, 983, 1053, 1113, 1167, 1177];
                LTy = [50, 240, 90, 193, 361, 279, 391, 195, 100, 277, 165, 80, 241, 95, 499, 549, 379, 461, 615, 505, 371];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                    
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
            
            
            
            if attrib(i, 4)==2   % SS 7 falling only in the FAR region from the lower left corner
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(21);
                LTx = [541, 563, 660, 650, 653, 725, 820, 787, 827, 900, 980, 1009, 1117, 1175, 850, 960, 983, 1053, 1113, 1167, 1177];
                LTy = [50, 240, 90, 193, 361, 279, 391, 195, 100, 277, 165, 80, 241, 95, 499, 549, 379, 461, 615, 505, 371];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                    
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
        end
        
    end
    
    
    if attrib(i, 1)==4           % When hand in lower right corner
        handX = 1280;
        handY = 1024;
        h_quad = 'LR';
        hand_quad = strvcat(hand_quad, h_quad);
        
        if attrib(i, 5)==1       % Target falling only in the NEAR region in the lower right corner
            t_quad = 'LR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Near';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4 in the near region in lower right corner
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(23);
                LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
                LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
            
            if attrib(i, 4)==2 % SS 7 in the near region in lower right corner
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(23);
                LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
                LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = strvcat(target_quad, t_quad);
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
            
            
        end
        
        if attrib(i, 5)==2       % Target falling only in the FAR region from the lower right corner
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Far';
            targ_dist = strvcat(targ_dist, t_dist);
            
            if attrib(i, 4)==1 % SS 4: target falling only in the far region in the lower right corner
                setsize = '4';
                setsize_cond = strvcat(setsize_cond,setsize);
                x1 = randperm(21);
                
                LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
                LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
                
                X = LTx(x1(1:4));
                Y = LTy(x1(1:4));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(4);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = cat(1, target_quad, t_quad);
                    
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
            
            if attrib(i, 4)==2 % SS 7: target falling only in the far region in the lower right corner
                setsize = '7';
                setsize_cond = strvcat(setsize_cond,setsize);
                
                x1 = randperm(21);
                LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
                LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
                
                X = LTx(x1(1:7));
                Y = LTy(x1(1:7));
                
                if attrib(i,3)==1
                    alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                    Target = 'E';
                    Target_cond = strvcat(Target_cond, Target);
                else
                    alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                    Target = 'F';
                    Target_cond = strvcat(Target_cond, Target);
                end
                
                digit_rand = randperm(7);
                
                if attrib(i,2)==1 %(ithu veno?? Target position information)
                    target_digit_index = find((digit_rand)==1);
                    first_quad = [1,2,3,4,5,6,7];
                    first_quad_rand = Shuffle(first_quad);
                    temp1 = digit_rand(first_quad_rand(1));
                    temp2 = first_quad_rand(1);
                    digit_rand(temp2)=1;
                    digit_rand(target_digit_index)=temp1;
                    
                    target_posX = X(find(digit_rand==1)); %#ok
                    target_posY = Y(find(digit_rand==1)); %#ok
                    
                    if attrib(i,1)~=0
                        t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                        target_dist = cat(1, target_dist, t_dist);
                    else
                        t_dist = 0;
                        target_dist = cat(1, target_dist, t_dist);
                    end
                    
                    %                     t_quad = '1';
                    %                     target_quad = cat(1, target_quad, t_quad);
                    
                end
                
                Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
                Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
                Screen(wPtr, 'Flip');
                
                startSecs = GetSecs;
                stopSecs = KbWait();
                [keyIsDown ctime keycodes] = KbCheck();
                
                if keycodes(kc_E)
                    k = E_key;
                    keypress = 'T';
                    
                elseif keycodes(kc_F)
                    k = F_key;
                    keypress = 'F';
                end
                
                if Target=='E' && keypress=='F'
                    feed = '1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                    
                elseif Target=='F' && keypress=='T'
                    feed='1';
                    text = 'Incorrect, Press any key to resume';
                    width=RectWidth(Screen('TextBounds',wPtr,text));
                    Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                    Screen(wPtr, 'Flip');
                    KbWait([],2);
                else feed = '0';
                end
                
                t1 = (stopSecs - startSecs);
                keys = strvcat(keys,k); %#ok
                time = cat(1,time,t1);
                feedback = cat(1,feedback, feed);
                
            end
        end
    end
    
    
    
    if attrib(i, 1)==5           % No-hand
        
        %         handX = 1152;
        %         handY = 0;
        h_quad = 'Nohand';
        hand_quad = strvcat(hand_quad, h_quad);
        
        if attrib(i, 5)==1 && attrib(i, 4)==1      % Target area is only near the upper right corner
            %             t_quad = '1-Near';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %             if attrib(i, 4)==1 % SS 4
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [541, 563, 660, 650, 653,   725, 820, 787, 827, 900,     980, 1009, 1117, 1175, 850,   960, 983, 1053, 1113,   1167, 1177];
            LTy = [50, 240, 90, 193, 361,     279, 391, 195, 100, 277,     165, 80, 241, 95, 499,        549, 379, 461, 615,     505, 371];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = cat(1, Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = cat(1, Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = strvcat(feedback, feed);
            %             end
            
            
            
            
        elseif attrib(i, 5)==1 && attrib(i, 4)==2 % SS 7
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [541, 563, 660, 650, 653,   725, 820, 787, 827, 900,     980, 1009, 1117, 1175, 850,   960, 983, 1053, 1113,   1167, 1177];
            LTy = [50, 240, 90, 193, 361,     279, 391, 195, 100, 277,     165, 80, 241, 95, 499,        549, 379, 461, 615,     505, 371];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M', 'N', 'P', 'Z'];
                Target = 'E';
                Target_cond = cat(1, Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M', 'N', 'P', 'Z'];
                Target = 'F';
                Target_cond = cat(1, Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = strvcat(feedback, feed);
            %         end
            
            
        elseif attrib(i, 5)==2 && attrib(i, 4)==1      % Target falling in the far region from the upper right corner
            %             t_quad = '1-Far';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'LL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %             if attrib(i, 4)==1 % SS 4
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(22);
            LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
            LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
                
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            
        elseif attrib(i, 5)==2 && attrib(i, 4)==2 % SS 7
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            t_quad = 'LL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(22);
            LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
            LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M', 'N', 'P', 'Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M', 'N', 'P', 'Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
                
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            %         end
            %     end
            
            
            %     if attrib(i, 1)==5           % No-hand
            %         handX = 0;
            %         handY = 0;
            %         h_quad = 'Nohand';
            %         hand_quad = strvcat(hand_quad, h_quad);
            
            
        elseif attrib(i, 5)==3 && attrib(i, 4)==1       % Target falling only in the NEAR region of the upper left corner
            %             t_quad = '2-Near';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'UL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %             if attrib(i, 4)==1 % SS 4
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
            LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            % end
            
            
            
        elseif attrib(i, 5)==3 && attrib(i, 4)==2 % SS 7
            t_quad = 'UL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
            LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            if attrib(i,2)==1
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            %         end
            %     end
            
            
            
        elseif attrib(i, 5)==4 &&  attrib(i, 4)==1      % Target falling only in the FAR region from the upper left corner
            %             t_quad = '2-Far';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'LR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %             if attrib(i, 4)==1 % SS 4
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(23);
            LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
            LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %             end
            
            
            
        elseif attrib(i, 5)==4 && attrib(i, 4)==2 % SS 7
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            t_quad = 'LR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(23);
            LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
            LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M', 'N','P','Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %         end
            
            
            
            
            % if attrib(i, 1)==7           % No-hand
            %         handX = 0;
            %         handY = 864;
            %     h_quad = 'Nohand';
            %     hand_quad = strvcat(hand_quad, h_quad);
            
        elseif attrib(i, 5)==5 && attrib(i, 4)==1      % Target falling only in the NEAR region in the lower left corner
            %             t_quad = '3-Near';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'LL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %         if attrib(i, 4)==1 % SS 4 in the NEAR region of the lower left corner
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(22);
            LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
            LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            %         end
            
        elseif attrib(i, 5)==5 && attrib(i, 4)==2 % SS 7 in the near region of lower left corner
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            t_quad = 'LL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(22);
            LTx = [70, 117, 231, 413, 303, 143,   71, 421, 525, 590, 300, 237,     90, 200, 330, 423, 369, 509,     535, 611, 677, 769];
            LTy = [253, 349, 367, 449, 471, 531    645, 541, 545, 633, 631, 719,   813, 907, 837, 695, 947, 865,    739, 921, 815, 931];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            %         end
            
            
            
        elseif attrib(i, 5)==6 && attrib(i, 4)==1       % Target falling only in the FAR region from the lower left corner
            %             t_quad = '3-Far';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %         if attrib(i, 4)==1 % SS 4 falling in the FAR region from the lower left corner
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [541, 563, 660, 650, 653, 725, 820, 787, 827, 900, 980, 1009, 1117, 1175, 850, 960, 983, 1053, 1113, 1167, 1177];
            LTy = [50, 240, 90, 193, 361, 279, 391, 195, 100, 277, 165, 80, 241, 95, 499, 549, 379, 461, 615, 505, 371];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %     end
            
            
            
        elseif attrib(i, 5)==6 && attrib(i, 4)==2   % SS 7 falling only in the FAR region from the lower left corner
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            t_quad = 'UR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [541, 563, 660, 650, 653, 725, 820, 787, 827, 900, 980, 1009, 1117, 1175, 850, 960, 983, 1053, 1113, 1167, 1177];
            LTy = [50, 240, 90, 193, 361, 279, 391, 195, 100, 277, 165, 80, 241, 95, 499, 549, 379, 461, 615, 505, 371];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
%                 t_quad = '1';
%                 target_quad = strvcat(target_quad, t_quad);
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %         end
            
            %     if attrib(i, 1)==7         % No-hand
            %         handX = 1152;
            %         handY = 864;
            %     h_quad = 'Nohand';
            %     hand_quad = strvcat(hand_quad, h_quad);
            
        elseif attrib(i, 5)==7 && attrib(i, 4)==1       % Target falling only in the NEAR region in the lower right corner
            %             t_quad = '4-Near';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'LR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %         if attrib(i, 4)==1 % SS 4 in the near region in lower right corner
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(23);
            LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
            LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    %                         t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    %                         target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %         end
            
        elseif attrib(i, 5)==7 && attrib(i, 4)==2 % SS 7 in the near region in lower right corner
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            t_quad = 'LR';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(23);
            LTx = [965, 905, 791,    975, 1135, 1037, 1153, 873,   1050, 997, 1169, 767, 713,     1169, 1127,  861,  595,   547, 671, 503, 367, 615, 770];
            LTy = [553, 861, 773,     673, 775, 851, 929, 723,     469, 375, 393, 595,   683,     505, 607,    491,  631    729, 815, 871, 955, 927, 927];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(target_quad, t_quad);
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %         end
            
            
        elseif attrib(i, 5)==8 && attrib(i, 4)==1       % Target falling only in the FAR region from the lower right corner
            %             t_quad = '4-Far';
            %             target_quad = strvcat(target_quad, t_quad);
            t_quad = 'UL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %         if attrib(i, 4)==1 % SS 4: target falling only in the far region from the lower right corner
            setsize = '4';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
            LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
            
            X = LTx(x1(1:4));
            Y = LTy(x1(1:4));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(4);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
            %         end
            
        elseif attrib(i, 5)==8 && attrib(i, 4)==2 % SS 7: target falling only in the far region from the lower right corner
            setsize = '7';
            setsize_cond = strvcat(setsize_cond,setsize);
            
            t_quad = 'UL';
            target_quad = strvcat(target_quad, t_quad);
            
            t_dist = 'Nohand';
            targ_dist = strvcat(targ_dist, t_dist);
            
            %                 t_quad = 'Nohand';
            %                 target_quad = strvcat(target_quad, t_quad);
            
            x1 = randperm(21);
            LTx = [585, 425, 543, 635,    670, 473, 425, 555, 421,     425, 355, 289, 287, 230,    167, 105, 73, 103, 221, 281, 73];
            LTy = [445, 539, 347, 200,    75, 109, 231, 237, 359,      447, 173, 257, 473, 365,    539, 363, 241, 107, 157, 65, 649];
            
            X = LTx(x1(1:7));
            Y = LTy(x1(1:7));
            
            if attrib(i,3)==1
                alphabets = ['E', 'H', 'L', 'M','N','P','Z'];
                Target = 'E';
                Target_cond = strvcat(Target_cond, Target);
            else
                alphabets = ['F', 'H', 'L', 'M','N','P','Z'];
                Target = 'F';
                Target_cond = strvcat(Target_cond, Target);
            end
            
            digit_rand = randperm(7);
            
            if attrib(i,2)==1 %(ithu veno?? Target position information)
                target_digit_index = find((digit_rand)==1);
                first_quad = [1,2,3,4,5,6,7];
                first_quad_rand = Shuffle(first_quad);
                temp1 = digit_rand(first_quad_rand(1));
                temp2 = first_quad_rand(1);
                digit_rand(temp2)=1;
                digit_rand(target_digit_index)=temp1;
                
                target_posX = X(find(digit_rand==1)); %#ok
                target_posY = Y(find(digit_rand==1)); %#ok
                
                if attrib(i,1)==0
                    t_dist = sqrt((target_posX-handX)^2 + (target_posY-handY)^2);
                    target_dist = cat(1, target_dist, t_dist);
                else
                    t_dist = 0;
                    target_dist = cat(1, target_dist, t_dist);
                end
                
                %                     t_quad = '1';
                %                     target_quad = strvcat(1, target_quad, t_quad);
                
            end
            
            Screen('DrawText', wPtr, alphabets(digit_rand(1)), X(1), Y(1),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(2)), X(2), Y(2),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(3)), X(3), Y(3),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(4)), X(4), Y(4),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(5)), X(5), Y(5),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(6)), X(6), Y(6),[255 255 255]);
            Screen('DrawText', wPtr, alphabets(digit_rand(7)), X(7), Y(7),[255 255 255]);
            Screen(wPtr, 'Flip');
            
            startSecs = GetSecs;
            stopSecs = KbWait();
            [keyIsDown ctime keycodes] = KbCheck();
            
            if keycodes(kc_E)
                k = E_key;
                keypress = 'T';
                
            elseif keycodes(kc_F)
                k = F_key;
                keypress = 'F';
            end
            
            if Target=='E' && keypress=='F'
                feed = '1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
                
            elseif Target=='F' && keypress=='T'
                feed='1';
                text = 'Incorrect, Press any key to resume';
                width=RectWidth(Screen('TextBounds',wPtr,text));
                Screen('DrawText', wPtr,text,xcenter-width/2, ycenter, [255 255 255]);
                Screen(wPtr, 'Flip');
                KbWait([],2);
            else feed = '0';
            end
            
            t1 = (stopSecs - startSecs);
            keys = strvcat(keys,k); %#ok
            time = cat(1,time,t1);
            feedback = cat(1,feedback, feed);
            
        end
    end
end
% end

Screen('TextSize', wPtr, 22);
Screen('TextStyle', wPtr , 1);
thank_text = 'Experiment Finished...Thanks!';
width_thank=RectWidth(Screen('TextBounds',wPtr,thank_text));
wait_text = 'Data is being written up in the file...please wait';
width_wait=RectWidth(Screen('TextBounds',wPtr,wait_text));
Screen('DrawText', wPtr,thank_text , xcenter-width_thank/2,300, [255 255 255]);
Screen('DrawText', wPtr,wait_text , xcenter-width_wait/2,400, [255 255 255]);
Screen(wPtr, 'Flip');
tic
while toc<1;
end

% handposside= cellstr(handpos);
HandQ= cellstr(hand_quad);
TargQ= cellstr(target_quad);
TD= cellstr(targ_dist);


% setsize_condcell = cellstr(setsize_cond);
header = {'S.No.', 'Hand Quad', 'TargQuad', 'TDist', 'RT', 'SS', 'Correct', 'Keypress'};
xlswrite(dbase, header, 1, 'A1')
xlswrite(dbase, sub_no, 1, 'A2:A501')
xlswrite(dbase, HandQ, 1, 'B2:B501')
xlswrite(dbase, TargQ, 1, 'C2:C501')
xlswrite(dbase, TD, 1, 'D2:D501')
xlswrite(dbase, time, 1, 'E2:E501')
xlswrite(dbase, setsize_cond, 1, 'F2:F501')
xlswrite(dbase, feedback, 1, 'G2:G501')
xlswrite(dbase, keys, 1, 'H2:H501')
% xlswrite(dbase, keys, 1, 'H2:H41')
% xlswrite(dbase, target_dist, 1, 'I2:I41')

Screen('CloseAll');