problem with coding for linear interpolation

6 Ansichten (letzte 30 Tage)
Erfan Dorodgar
Erfan Dorodgar am 23 Nov. 2021
Kommentiert: KSSV am 23 Nov. 2021
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 Kommentar
KSSV
KSSV am 23 Nov. 2021
The condition
distance>1
is always met as the value of distance = 4 is fixed always and not changing.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by