# Need suggestions

**URL:** https://psychtoolbox.discourse.group/t/need-suggestions/1708
**Category:** Uncategorized
**Created:** [November 10, 2004, 3:16pm UTC](https://psychtoolbox.discourse.group/t/need-suggestions/1708 "2004-11-10T15:16:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jiansongxu](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jiansongxu](https://psychtoolbox.discourse.group/u/jiansongxu)
#### Post date: [November 10, 2004, 3:16pm UTC](https://psychtoolbox.discourse.group/t/need-suggestions/1708/1 "2004-11-10T15:16:10Z")

</div>

Dear Friend:  
  
 I want to display stimulus for 1 second, and 2 seconds blank screen, so the  
total inter-stimuli interval is 3 seconds. In the following codes, I try to  
use the out while loop for inter-stimuli interval, and the inner loop for  
display time. The problem is the stimulus "red" was displayed for 3 seconds  
instead of 1.   
  
Any comments are appreciated. Once again, it will be great if any one can  
send me some programs for me to study. I have studied all the demo programs.  
  
Jiansong Xu  
  
  
 w=Screen('OpenWindow', screenNumber,0,[],32,2);  
 Screen('FillRect', w, white);  
 Screen('TextFont',w, 'Courier');  
 Screen('TextSize',w, 50);  
 Screen('TextStyle', w, 0);  
  
 isi\_start = GetSecs;  
 isi\_duration = 0; % inter-stimuli interval  
  
 display\_end = 0; % display time  
  
 while isi\_duration \< 3000  
  
 display\_start = GetSecs;  
  
  
 while display\_end \< 1000  
 Screen('DrawText', w, 'red', 530, 530, [255,0,0]);  
 Screen('Flip',w);  
  
 display\_end = (GetSecs - display\_start)\*1000;  
 end  
 Screen('DrawText', w, ' ', 530, 530, [255,0,0]);  
  
 isi\_duration = (GetSecs - isi\_start)\*1000;  
 display\_end = (GetSecs - display\_start)\*1000;  
  
 end

---

<div class="post-metadata">

### Author: ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)
#### Post date: [November 11, 2004, 10:13am UTC](https://psychtoolbox.discourse.group/t/need-suggestions/1708/2 "2004-11-11T10:13:04Z")

</div>

Am 10.11.2004 um 16:16 schrieb Jiansong Xu:  

> \> Dear Friend:  
> \>  
> \> I want to display stimulus for 1 second, and 2 seconds blank screen,   
> \> so the  
> \> total inter-stimuli interval is 3 seconds. In the following codes, I   
> \> try to  
> \> use the out while loop for inter-stimuli interval, and the inner loop   
> \> for  
> \> display time. The problem is the stimulus "red" was displayed for 3   
> \> seconds  
> \> instead of 1.  
>    
> \> while isi\_duration \< 3000  
> \> while display\_end \< 1000  
> \> Screen('DrawText', w, 'red', 530, 530, [255,0,0]);  
> \> Screen('Flip',w);  
> \> display\_end = (GetSecs - display\_start)\*1000;  
> \> end  
> \> Screen('DrawText', w, ' ', 530, 530, [255,0,0])  
> \> isi\_duration = (GetSecs - isi\_start)\*1000;  
> \> display\_end = (GetSecs - display\_start)\*1000;  
> \> end  
>    
> \> Any comments are appreciated. Once again, it will be great if any one   
> \> can  
> \> send me some programs for me to study. I have studied all the demo   
> \> programs.  
> \>  
> \> Jiansong Xu

Hi,  
  
I think the stimulus "red" was shown for three seconds because you did   
not include a "screen('flip") statement after the second call to   
DrawText.  
You can also save many function calls. First, because you are using   
static stimuli, there is no need to redraw the screen on every pass   
through the loop. Instead, just use drawing calls when things are   
supposed to change, as shown in the example below. Second, getsecs   
needs to be called only once within the loop.  
  
hth, jochen  
  
try  
 white=[255 255 255];  
 w=Screen('OpenWindow', screenNumber,0,[],32,2);  
 Screen('FillRect', w, white);  
 Screen('TextFont',w, 'Courier');  
 Screen('TextSize',w, 50);  
 Screen('TextStyle', w, 0);  
  
 MS2S = 1/1000; % milliseconds to seconds factor  
 ISI\_DURATION = 3000\*MS2S; % inter-stimuli interval  
 STIM\_DURATION = 1000\*MS2S; % display time  
  
 stimTimeExceeded=0; % flag: is stimulus time exceeded? (logical)  
 t = 0;  
 Screen('DrawText', w, 'red', 530, 530, [255,0,0]);  
 Screen('Flip',w);  
 t0 = GetSecs;  
 while t \< ISI\_DURATION  
 if ~stimTimeExceeded  
 if t \>= STIM\_DURATION  
 Screen('DrawText', w, ' ', 530, 530, [255,0,0]);  
 Screen('Flip',w);  
 stimTimeExceeded=1;  
 end  
 end  
 t = GetSecs-t0;  
 end  
 screen('CloseAll');  
catch  
 Screen('CloseAll');  
 ShowCursor;  
end

---

<div class="post-metadata">

### Author: ![jiansongxu](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jiansongxu](https://psychtoolbox.discourse.group/u/jiansongxu)
#### Post date: [November 11, 2004, 7:17pm UTC](https://psychtoolbox.discourse.group/t/need-suggestions/1708/3 "2004-11-11T19:17:13Z")

</div>

Hi, Jochen:  
  
Thanks a lot. One more question (a lot more in the near future till no one  
want to response). Where should I put KbCheck to measure the reaction time?  
  
Best Wishes  
  
Jiansong   
  

> \> From: Jochen Laubrock \<[laubrock@...](mailto:laubrock@...)-potsdam.de\>  
> \> Date: Thu, 11 Nov 2004 11:13:04 +0100  
> \> To: [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com)  
> \> Cc: Jiansong Xu \<[jiansong@...](mailto:jiansong@...)\>  
> \> Subject: Re: [psychtoolbox] Need suggestions (OS X)  
> \>   
> \> Am 10.11.2004 um 16:16 schrieb Jiansong Xu:  
> \>\> Dear Friend:  
> \>\>   
> \>\> I want to display stimulus for 1 second, and 2 seconds blank screen,  
> \>\> so the  
> \>\> total inter-stimuli interval is 3 seconds. In the following codes, I  
> \>\> try to  
> \>\> use the out while loop for inter-stimuli interval, and the inner loop  
> \>\> for  
> \>\> display time. The problem is the stimulus "red" was displayed for 3  
> \>\> seconds  
> \>\> instead of 1.  
> \>   
> \>\> while isi\_duration \< 3000  
> \>\> while display\_end \< 1000  
> \>\> Screen('DrawText', w, 'red', 530, 530, [255,0,0]);  
> \>\> Screen('Flip',w);  
> \>\> display\_end = (GetSecs - display\_start)\*1000;  
> \>\> end  
> \>\> Screen('DrawText', w, ' ', 530, 530, [255,0,0])  
> \>\> isi\_duration = (GetSecs - isi\_start)\*1000;  
> \>\> display\_end = (GetSecs - display\_start)\*1000;  
> \>\> end  
> \>   
> \>\> Any comments are appreciated. Once again, it will be great if any one  
> \>\> can  
> \>\> send me some programs for me to study. I have studied all the demo  
> \>\> programs.  
> \>\>   
> \>\> Jiansong Xu  
> \>   
> \> Hi,  
> \>   
> \> I think the stimulus "red" was shown for three seconds because you did  
> \> not include a "screen('flip") statement after the second call to  
> \> DrawText.  
> \> You can also save many function calls. First, because you are using  
> \> static stimuli, there is no need to redraw the screen on every pass  
> \> through the loop. Instead, just use drawing calls when things are  
> \> supposed to change, as shown in the example below. Second, getsecs  
> \> needs to be called only once within the loop.  
> \>   
> \> hth, jochen  
> \>   
> \> try  
> \> white=[255 255 255];  
> \> w=Screen('OpenWindow', screenNumber,0,[],32,2);  
> \> Screen('FillRect', w, white);  
> \> Screen('TextFont',w, 'Courier');  
> \> Screen('TextSize',w, 50);  
> \> Screen('TextStyle', w, 0);  
> \>   
> \> MS2S = 1/1000; % milliseconds to seconds factor  
> \> ISI\_DURATION = 3000\*MS2S; % inter-stimuli interval  
> \> STIM\_DURATION = 1000\*MS2S; % display time  
> \>   
> \> stimTimeExceeded=0; % flag: is stimulus time exceeded? (logical)  
> \> t = 0;  
> \> Screen('DrawText', w, 'red', 530, 530, [255,0,0]);  
> \> Screen('Flip',w);  
> \> t0 = GetSecs;  
> \> while t \< ISI\_DURATION  
> \> if ~stimTimeExceeded  
> \> if t \>= STIM\_DURATION  
> \> Screen('DrawText', w, ' ', 530, 530, [255,0,0]);  
> \> Screen('Flip',w);  
> \> stimTimeExceeded=1;  
> \> end  
> \> end  
> \> t = GetSecs-t0;  
> \> end  
> \> screen('CloseAll');  
> \> catch  
> \> Screen('CloseAll');  
> \> ShowCursor;  
> \> end
