MATLAB: What is wrong in this code?

griddatainterpolationoptimizationproblemwhile loop

Could you please help me to solve the problem? Loop cannot stop.
Attached you can find the file. The function is digdata and the other is code. Thank you.

Best Answer

In this loop:
while abs(res1)>0.01
As = vq.*(Us(j).^2)./(16.*(pi.^2).*msksi.*fs1(j));
res1 = As1(i)-As;
end
you calculate the same value in each iteration. As will never change its value. Therefore this must be an infinite loop.
Due to the missing comments, the purpose of this loop cannot be guessed. Therefore a reliable suggestion of improvement cannot be given.