Matlab mysteriously stops running mid script; deleting some simple code makes it run again, but I need that code!

32 次查看(过去 30 天)
Hi all, I have been having quite a perplexing problem. After making a small, almost arbitrary change to a piece of code, matlab stops running several hunderd lines after the altered piece of code. There's no error message, the program just becomes unresponsive. Here's a schematic of what I changed.
Version 1: (works fine)
Function MyFunction
.
.
if A
Do X
elseif B
Do Y
Do Z
% elseif B
% Do Y
end
.
.
end
Version 2 (does not work)
Function MyFunction
.
.
if A
Do X
%elseif B
% Do Y
% Do Z
elseif B
Do Y
end
.
.
end
As you can see, the only change is that I effectively deleted a portion of code by uncommenting several lines and commenting others. Everything that's in the uncommented section in version 2 was also already taking place in version 1.
In my case, the 'Do Z' which is omitted from version 2 is the playback of a sound stimulus via the PsychToolbox PsychPortAudio function. I'm doing this in multiple scripts in various ways and it works fine.
What happens is that in the second version, the script runs past this part without any problems, as expected, but when it comes to a different part of the script, unrelated to this, around 300 lines downstream, it just stops. For no reason. I've been trying to debug to no avail. I've been putting markers there to display so I can track where the program stops working, and even when I don't give matlab anything else to do for 300 lines other than display letters (using 'disp('a')' 'disp('b')' etc.) it just stops running at the same point every single time.
So I have the impression there's some kind of interference between the Psychtoolbox and Matlab, but I have no way of figuring out and the entire thing feels very arbitrary. I've actually had this happening before and then I thought it was because of communications with an FPGA were interfering in some way with Matlab; then I solved it by adding lines with arbitrarily small pauses in between the seemingly involved lines of code. That isn't working now which is why I'm posting this message. I would be really curious to learn if anyone has come accross similar problems. At the moment I'm thinking I should just make other random additions or omissions to the code in hopes of simply skipping over some invisible bump. But that isn't a very satisyfing solution.
Thanks a lot in advance and again, hope you can help.
My system: Windows 7 Professional 64-bit Matlab R2007b intel Core i7 2600K 8GB DD3 RAM

回答(1 个)

Paul
Paul 2013-3-29
Hi all, I found the issue. Commenting out 'Do Y' led to a playback command to PsychPortAudio being suspended indefinitely. In the 'Do Y' part, there was a 'Stop playback' command which cleared the suspended audio from the buffer.
The program crashed as I gave PsychPortAudio an additional command to load new audio into the buffer, without cleaning the buffer first.
The peculiar thing was that the program seemingly became unresponsive several lines before it reached my command to load additional audio, probably due to some kind of a stack mismatch where matlab is executing code several lines ahead without reporting this in the command window.

类别

Help CenterFile Exchange 中查找有关 Installation and Operational Settings 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by