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:100for y=1:100curr=squeeze(data(y,x,:));[pcurr,f]=pwelch(curr,[],[],[],1);pp=polyfit(log10(f),log10(pcurr),1);m(y,x)=pp(1);endend
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