In your loop you have
while i==n
a=sum(y)/n;
cel = sprintf('A%i', i+2);
xlswrite('d:\Office.xls',a,1,cel);
end
but inside that loop you do not change "i" and you do not change "n" so if the loop condition is ever true it will remain true and you infinite loop.