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
2021년 11월 23일
The condition
distance>1
is always met as the value of distance = 4 is fixed always and not changing.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!