MATLAB: Short function taking 20+ minutes to run

MATLABnested loops

I'm using a Xeon quad-core processor with 64GB of RAM. The program running the function only has 89 data points. It's now been over 20 minutes and MATLAB is still "busy" computing the program. Does my code below reveal any reason why it's taking so long to compute?
function last15MinsOfDay=last15MinsOfDay(time,price)
% last15MinsOfDay takes the average of prices between 3:45 and 4:00.
timeStr=cellstr(datestr(time));
timeDbl=datevec(timeStr);
times=and(timeDbl(:,4)==14,timeDbl(:,5)>=45)+and(timeDbl(:,4)==15,timeDbl(:,5)==0);
priceIdx=find(times);
z=find(fwdshift(1,priceIdx)~=priceIdx+1);
z=[1; z];
mu=zeros(length(z),1);
for i = 1:length(z);
while i < length(z)
mu(i)=mean(price(priceIdx(z(i):z(i+1))));
end
end
last15MinsOfDay=mu;

Best Answer

When your code hits this line:
while i < length(z)
the value of i is 1, and the length of z is whatever it is. The condition will always be true, because i and z do not change. Therefore, you will never break out of that while loop.
Not sure what you intended, but the while loop seems completely unnecessary here.