problem with coding for linear interpolation

6 次查看(过去 30 天)
Hello all,
I am new to matlab and I am running this code but it is not running at all and the loop won't end. Can you please help me why this happens?
blow = -2;
bhigh = 4;
bnum = 10;
lb = log(blow-blow+1.0)/log(10);
ub = log(bhigh-blow+1.0)/log(10);
bgrid = logspace(lb,ub,bnum);
bgrid = bgrid+ones(size(bgrid))*(blow-1.0);
for i=1:1:bnum
bfval = bgrid(i);
ilow = 1; ihigh = 10;
distance=2;
value = bfval;
while (distance>1)
if (value>-0.6254)
ilow=5;
else
ihigh = 5;
end
distance = ihigh- ilow;
end
iloc = ilow;
if (value > bgrid(iloc))&&(value<bgrid(iloc+1))
weight = (bgrid(iloc+1)-value)/(bgrid(iloc+1)-bgrid(iloc));
elseif (value<=grid(1))
weight = 1; iloc = 1;
else
weight = 0; iloc = 9;
end
end
Thank you so much for your help.
  1 个评论
KSSV
KSSV 2021-11-23
The condition
distance>1
is always met as the value of distance = 4 is fixed always and not changing.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by