# Matlab hangs randomly when accessing psychtoolbox in a loop

**URL:** <https://psychtoolbox.discourse.group/t/matlab-hangs-randomly-when-accessing-psychtoolbox-in-a-loop/595>\
**Category:** Uncategorized\
**Created:** [April 11, 2017, 5:39am UTC](https://psychtoolbox.discourse.group/t/matlab-hangs-randomly-when-accessing-psychtoolbox-in-a-loop/595 "2017-04-11T05:39:36Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [April 11, 2017, 5:39am UTC](https://psychtoolbox.discourse.group/t/matlab-hangs-randomly-when-accessing-psychtoolbox-in-a-loop/595/1 "2017-04-11T05:39:36Z")

</div>

I am running some behavioral experiments and using psychtoolbox to present sinusoidal gratings on the screen and then activating water delivery using a NIDAQ board. This happens for multiple trials and is therefore in a loop. The problem I am facing is that Matlab will randomly hang within the loop and using print statements I have narrowed down the problem to executing the "flip" command. I have tried many of the recommended solutions including reinstalling Matlab and Psychtoolbox. This code was working and now doesnt and nothing has changed on the computer. Since Matlab hangs and it says that the PTB window is unresponsive I simply have to quit Matlab and restart and thus I have no access to the error.

Has this error been reported? Any suggestions / debugging ideas ?

Thanks!

Anu

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [April 11, 2017, 9:19pm UTC](https://psychtoolbox.discourse.group/t/matlab-hangs-randomly-when-accessing-psychtoolbox-in-a-loop/595/2 "2017-04-11T21:19:35Z")

</div>

I don't think we know of a bug like you describe it.  
Operating system? Windows? PTB 3.0.14 installed and up to date? System and gpu specs? Debug output (use the "diary on" command)? Sample code that fails? Multi-display setup?  
  
Something has changed on your system, maybe some setting, maybe some operating system update?  

-mario  
  
XX---In PSYCHTOOLBOX@yahoogroups.com, \<anubhuthi@...\> wrote :  
  

I am running some behavioral experiments and using psychtoolbox to present sinusoidal gratings on the screen and then activating water delivery using a NIDAQ board. This happens for multiple trials and is therefore in a loop. The problem I am facing is that Matlab will randomly hang within the loop and using print statements I have narrowed down the problem to executing the "flip" command. I have tried many of the recommended solutions including reinstalling Matlab and Psychtoolbox. This code was working and now doesnt and nothing has changed on the computer. Since Matlab hangs and it says that the PTB window is unresponsive I simply have to quit Matlab and restart and thus I have no access to the error.

Has this error been reported? Any suggestions / debugging ideas ?

Thanks!

Anu

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [April 12, 2017, 12:50pm UTC](https://psychtoolbox.discourse.group/t/matlab-hangs-randomly-when-accessing-psychtoolbox-in-a-loop/595/3 "2017-04-12T12:50:33Z")

</div>

try putting your code in:
  

try 

% your code here

catch ME

sca;

rethrow(ME);

end

  

Perhaps an error occurs, and you're stuck with an open screen

  

Cheers,

Dee

  

> On Tue, Apr 11, 2017 at 11:19 PM, [mario.kleiner@...](mailto:mario.kleiner@...) [PSYCHTOOLBOX] \<[PSYCHTOOLBOX@yahoogroups.com](mailto:PSYCHTOOLBOX@yahoogroups.com)\> wrote:  
> 
> > I don't think we know of a bug like you describe it.  
> > Operating system? Windows? PTB 3.0.14 installed and up to date? System and gpu specs? Debug output (use the "diary on" command)? Sample code that fails? Multi-display setup?  
> >   
> > Something has changed on your system, maybe some setting, maybe some operating system update?  
> > 
> > -mario  
> >   
> > XX---In [PSYCHTOOLBOX@yahoogroups.com](mailto:PSYCHTOOLBOX@yahoogroups.com), \<anubhuthi@...\> wrote :  
> >   
> > 
> > I am running some behavioral experiments and using psychtoolbox to present sinusoidal gratings on the screen and then activating water delivery using a NIDAQ board. This happens for multiple trials and is therefore in a loop. The problem I am facing is that Matlab will randomly hang within the loop and using print statements I have narrowed down the problem to executing the "flip" command. I have tried many of the recommended solutions including reinstalling Matlab and Psychtoolbox. This code was working and now doesnt and nothing has changed on the computer. Since Matlab hangs and it says that the PTB window is unresponsive I simply have to quit Matlab and restart and thus I have no access to the error.
> > 
> > Has this error been reported? Any suggestions / debugging ideas ?
> > 
> > Thanks!
> > 
> > Anu
