MATLAB: For loop pauses and restarts randomly

for loophalted code

I have a simple code (below) that contains two for loops. This code computes the power spectrum of a signal and fits a slope to the log-log spectrum.
m=zeros(100,100);
for x=1:100
for y=1:100
curr=squeeze(data(y,x,:));
[pcurr,f]=pwelch(curr,[],[],[],1);
pp=polyfit(log10(f),log10(pcurr),1);
m(y,x)=pp(1);
end
end
The code will run and use up about 60% of the CPU for some amount of time, 30 seconds is probably about the max, and then will pause and do nothing for a seemingly random amount of time, sometimes 5-10 minutes or longer before it starts up again and runs for a few seconds. The total run time should only be a few minutes, but it ends up taking hours.
This doesn't happen with only this code, but with other functions inside a for-loop that will utilize more then one processor at a time such as 'imfilter'. It will also happens when I run the code as a function or in the command window.
I am running Matlab r2011b on a 12-core Intel system.
If anyone has any idea what I could do so that the program does not pause please let me know.

Best Answer

Without looking at your code in detail, I can say that that behavior is typical of what happens when the memory needed by your code transitions from RAM into virtual memory. The bottleneck becomes the memory access, so the CPU usage drops radically. You might want to look at memory usage.
(I don't have the signal processing toolbox, so I can't investigate more.)