DrawTextures is not presenting stimuli within a for loop and conditional statement

if true
% Setup PTB with some default values
PsychDefaultSetup(2);
% Set the screen number to the external secondary monitor if there is one
% connected
screenNumber = max(Screen('Screens'));
% Define black, white and grey
Num_trial = 2;
%specify number of trials
Trial_post = randi([1, 2], [Num_trial,1]);
%randomly pick position left (1) or right (2)
white = WhiteIndex(screenNumber);
grey = white / 2;
% Skip sync tests for demo purposes only
Screen('Preference', 'SkipSyncTests', 2);
% Open the screen
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [], 32, 2,...
  [], [],  kPsychNeed32BPCFloat);
% Dimension of the region where will draw the Gabor in pixels
gaborDimPix = windowRect(4) / 2;
% Sigma of Gaussian
sigma = gaborDimPix / 7;
% Obvious Parameters
orientation = 0;
contrast = 1;
aspectRatio = 1.0;
phase = 0;
% Spatial Frequency (Cycles Per Pixel)
% One Cycle = Grey-Black-Grey-White-Grey i.e. One Black and One White Lobe
numCycles = 5;
freq = numCycles / gaborDimPix;
% Build a procedural gabor texture (Note: to get a "standard" Gabor patch
% we set a grey background offset, disable normalisation, and set a
% pre-contrast multiplier of 0.5.
backgroundOffset = [0.5 0.5 0.5 0.0];
disableNorm = 1;
preContrastMultiplier = 0.5;
gabortex = CreateProceduralGabor(window, gaborDimPix, gaborDimPix, [],...
  backgroundOffset, disableNorm, preContrastMultiplier);
% Randomise the phase of the Gabors and make a properties matrix.
propertiesMat = [phase, freq, sigma, contrast, aspectRatio, 0, 0, 0];
% Draw the Gabor. By default PTB will draw this in the center of the screen
% for us.
for i = 1:length(Trial_post)
if (Trial_post(i) == 1) == 1
Screen('DrawTextures', window, gabortex, [], [(windowRect(3)/2)-800, (windowRect(4)/2)+100 , (windowRect(3)/2)-100, (windowRect(4)/2)-100 ], orientation, [], [], [], [],...
  kPsychDontDoRotation, propertiesMat');
elseif (Trial_post(i) == 2) == 1
Screen('DrawTextures', window, gabortex, [], [(windowRect(3)/2)+100, (windowRect(4)/2)+100 , (windowRect(3)/2)+800, (windowRect(4)/2)-100 ], orientation, [], [], [], [],...
  kPsychDontDoRotation, propertiesMat');
end

respod(i) = input('Press 1 for appeared in the left or 2 for appeared in the right');
end
% Flip to the screen 
Screen('Flip', window);
% Wait for a button press to exit

KbWait;

% Clear screen
sca;
end

I am trying to randomly display a gabor stimuli either to the left or the right for each trial and have the user state where he/she saw the stimuli. However, when the algorithm runs it does not display the gabor stimuli within the forloop and conditional statement. But when you have one screen DrawTexture with no foorloop and no conditional statement it displays the stimuli.

You need to call Screen(‘Flip’) to actually show things that you have drawn. So that needs to be inside the loop. You will also need to time each flip such that there is sufficient time between them so that participants can actually see your Gabor (I assume you have a target presentaiton time?)

if true
% Setup PTB with some default values
PsychDefaultSetup(2);
% Set the screen number to the external secondary monitor if there is one
% connected
screenNumber = max(Screen('Screens'));

Num_trial = 40;
%specify number of trials
Trial_post = randi([1, 2], [Num_trial,1]);
%randomly pick position left (1) or right (2)
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
% Define black, white and grey
% Skip sync tests for demo purposes only
Screen('Preference', 'SkipSyncTests', 2);
% Open the screen
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [], 32, 2,...
  [], [],  kPsychNeed32BPCFloat);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Here we set the size of the arms of our fixation cross
fixCrossDimPix = 40;
% Now we set the coordinates (thesQP.update(targ, anscorrect);e are all relative to zero we will let
% the drawing routine center the cross in the center of our monitor for us)
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
% Set the line width for our fixation cross
lineWidthPix = 4;
fixRect = CenterRect([0 0 1 1] * 8, windowRect);
% define an 8 x 8 pixel fixation
% create another fixation stimulus of horizontal and
% vertical cross hairs outside the area of the sine wave
% pattern. Crosshairs will be displayed during display
% intervals
fixLen = 32; % length of fixation in pixels

% Draw the fixation cross in white, set it to the center of our screen and
% set good quality antialiasing
%Screen('DrawLines', window, allCoords,...
%    lineWidthPix, black, [xCenter yCenter]);

% Dimension of the region where will draw the Gabor in pixels
gaborDimPix = windowRect(4) / 2;

% Create another fixation stimulus of horizontal and
% vertical cross hairs outside the area of the gabor
% pattern. 
fixXY_L = [[-1 0 0 1] * fixLen + [-1 -1 1 1 ] * gaborDimPix/2 + ...
(windowRect(3)/2 -400) [1 1 1 1]*(windowRect(3)/2 - 400); ...
[1 1 1 1]*(windowRect(4)/2) [-1 0 0 1] *fixLen + ...
[-1 -1 1 1 ] * gaborDimPix/2 + (windowRect(4)/2)];

fixXY_R = [[-1 0 0 1] * fixLen + [-1 -1 1 1 ] * gaborDimPix/2 + ...
(windowRect(3)/2 +400) [1 1 1 1]*(windowRect(3)/2 + 400); ...
[1 1 1 1]*(windowRect(4)/2) [-1 0 0 1] *fixLen + ...
[-1 -1 1 1 ] * gaborDimPix/2 + (windowRect(4)/2)];

gaborDimPix_s = windowRect(4) / 20;
% Sigma of Gaussian
sigma = gaborDimPix_s / 7;
% Obvious Parameters
orientation = 45;
contrast = 1;
aspectRatio = 1.0;
phase = 0;
% Spatial Frequency (Cycles Per Pixel)
% One Cycle = Grey-Black-Grey-White-Grey i.e. One Black and One White Lobe
numCycles = 10;
freq = numCycles / gaborDimPix_s;
% Build a procedural gabor texture (Note: to get a "standard" Gabor patch
% we set a grey background offset, disable normalisation, and set a
% pre-contrast multiplier of 0.5.
backgroundOffset = [0.5 0.5 0.5 0];
disableNorm = 1;

p.ScreenDistance = 30; % in inches
p.ScreenHeight = 15; % in inches
p.ScreenGamma = 2; % from monitor calibration
p.maxLuminance = 100; % from monitor calibration
p.ScreenBackground = 0.5;
p.sf = 1;
% Compute stimulus parameters
ppd = pi/180 * p.ScreenDistance / p.ScreenHeight * windowRect(4);
% compute pixels per degree from
% p.ScreenDistance and p.ScreenHeight
p.stimSize = 6; % image diameter in visual degree
sf = p.sf / ppd; % compute spatial frequency in
% cycles per pixel
m = round(p.stimSize * ppd /2) * 2; % stimulus size
% in pixels
%preContrastMultiplier = 0.5;
tex = CreateProceduralSineGrating(window, m, m, [[1 1 1]*p.ScreenBackground 0], m/2, 0.5);
%gabortex = CreateProceduralGabor(window, gaborDimPix_s, gaborDimPix_s, [],...
%  backgroundOffset, disableNorm, preContrastMultiplier);
% Randomise the phase of the Gabors and make a properties matrix.
%propertiesMat = [phase, freq, sigma, contrast, aspectRatio, 0, 0, 0];
% Draw the Gabor. By default PTB will draw this in the center of the screen
% for us.

% set Quest+ procedure
% F = @(x,mu)([1-normcdf(x,mu,1),normcdf(x,mu,1)])';
%  % create QUEST+ object
 stimDomain = [0:.00001:.009, .01:.02:.09, .10:.03:.20];%exp(linspace(log(0.001),log(10),60))./50
% paramDomain = exp(linspace(log(0.01),log(10),60))./50;
% respDomain    	= [0 1];
 %stopRule       	= 'ntrials';
 %stopCriterion  	= length(Trial_post);
 
% QP = QuestPlus(F, stimDomain, paramDomain, respDomain, stopRule, stopCriterion);
% % initialise (with default, uniform, prior)
% QP.initialise();
currentcontNum =  length(stimDomain); %length(stimDomain);
correctInARow = 0; 

for i = 1:length(Trial_post)
% targ = QP.getTargetStim();  
 contrast(i) = stimDomain(currentcontNum);
 %propertiesMat = [phase, freq, sigma, contrast(i), aspectRatio, 0, 0, 0];
 propertiesMat = [180 sf contrast(i) 0 ];
if (Trial_post(i) == 1) == 1
  Screen('Flip', window);
  Screen( 'DrawLines' , window, fixXY_R, 3, 0.3);  
 Screen( 'DrawLines' , window, fixXY_L, 3, 0.3);    
Screen('DrawLines', window, allCoords,...
    lineWidthPix, black, [xCenter yCenter]);
%gabortex = CreateProceduralGabor(window, gaborDimPix_s, gaborDimPix_s, [],...
 % backgroundOffset, disableNorm, contrast(i));

Screen('DrawTextures', window, tex, [], [(windowRect(3)/2)-floor(windowRect(3)/2.9538), (windowRect(4)/2)+(windowRect(4)/4), (windowRect(3)/2)-windowRect(3)/12.8, (windowRect(4)/2)-(windowRect(4)/4)], orientation, [], [], [], [],...
  kPsychDontDoRotation, propertiesMat');
Screen('Flip', window, 0.1);
elseif (Trial_post(i) == 2) == 1
 Screen('Flip', window);
 Screen( 'DrawLines' , window, fixXY_R, 3, 0.3);
 Screen( 'DrawLines' , window, fixXY_L, 3, 0.3);   
Screen('DrawLines', window, allCoords,...
    lineWidthPix, black, [xCenter yCenter]);
%gabortex = CreateProceduralGabor(window, gaborDimPix_s, gaborDimPix_s, [],...
 % backgroundOffset, disableNorm, contrast(i));
 
Screen('DrawTextures', window, tex, [], [(windowRect(3)/2)+(windowRect(3)/12.800), (windowRect(4)/2)+(windowRect(4)/4) , (windowRect(3)/2)+floor(windowRect(3)/2.9538), (windowRect(4)/2)-(windowRect(4)/4)], orientation, [], [], [], [],...
  kPsychDontDoRotation, propertiesMat');
Screen('Flip', window, 0.1);
end

disp('Press 1 for appeared in the left or 2 for appeared in the right') 
w = waitforbuttonpress;

respod(i) = str2num(get(gcf, 'CurrentCharacter'));

%respod(i) = input('Press 1 for appeared in the left or 2 for appeared in the right');
if strcmp(num2str(respod(i)) , '3' ), break; end
anscorrect(i) = (respod(i) == Trial_post(i));
    if anscorrect(i) == 0; %incorrect
        if currentcontNum ~= length(stimDomain)
            currentcontNum = currentcontNum+1; %make it easier
        else
            currentcontNum = length(stimDomain);
        end
        correctInARow = 0;
    else
        correctInARow = correctInARow+1;
        if correctInARow == 2
            if currentcontNum ~= 1
                currentcontNum = currentcontNum-1; %make it harder
            else
                currentcontNum = 1;
            end
            correctInARow = 0;
        end
    end
%if anscorrect(i), Beeper; end % beep if correct
%QP.update(targ, anscorrect(i));
end
a.cont = contrast;
a.resp = respod;

save contrastsensitivity.mat a;
% Flip to the screen 
%Screen('Flip', window);
% Wait for a button press to exit

KbWait;

% Clear screen
sca;
end

Thanks, Now how do I make it so that the gabors presentation time is only 100ms?