problem with coding for linear interpolation

조회 수: 6 (최근 30일)
Erfan Dorodgar
Erfan Dorodgar 2021년 11월 23일
댓글: KSSV 2021년 11월 23일
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